Part Number Hot Search : 
CPH5862 30CPQ10 74HC24 M1001 4066BF MAX4063 AD7346B ISL82
Product Description
Full Text Search
 

To Download PIC24F04KA200T-IMQ Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  ? 2009 microchip technology inc. preliminary ds39937b pic24f04ka201 family data sheet 14/20-pin general purpose, 16-bit flash microcontrollers with nanowatt xlp? technology
ds39937b-page ii preliminary ? 2009 microchip technology inc. information contained in this publication regarding device applications and the like is provided only for your convenience and may be superseded by updates. it is your responsibility to ensure that your application meets with your specifications. microchip makes no representations or warranties of any kind whether express or implied, written or oral, statutory or otherwise, related to the information, including but not limited to its condition, quality, performance, merchantability or fitness for purpose . microchip disclaims all liability arising from this information and its use. use of microchip devices in life support and/or safety applications is entirely at the buyer?s risk, and the buyer agrees to defend, indemnify and hold harmless microchip from any and all damages, claims, suits, or expenses resulting from such use. no licenses are conveyed, implicitly or otherwise, under any microchip intellectual property rights. trademarks the microchip name and logo, the microchip logo, accuron, dspic, k ee l oq , k ee l oq logo, mplab, pic, picmicro, picstart, rfpic, smartshunt and uni/o are registered trademarks of microchip tec hnology incorporated in the u.s.a. and other countries. filterlab, hampshire, linear active thermistor, mxdev, mxlab, seeval, smartsensor and the embedded control solutions company are registered trademarks of microchip technology incorporated in the u.s.a. analog-for-the-digital age, appl ication maestro, codeguard, dspicdem, dspicdem.net, dspicworks, dsspeak, ecan, economonitor, fansense, in-circuit serial programming, icsp, icepic, mindi, miwi, mpasm, mplab certified logo, mplib, mplink, mtouch, nanowatt xlp, pickit, picdem, picdem.net, pictail, pic 32 logo, powercal, powerinfo, powermate, powertool, real ice, rflab, select mode, total endurance, tsha rc, wiperlock and zena are trademarks of microchip tec hnology incorporated in the u.s.a. and other countries. sqtp is a service mark of microchip technology incorporated in the u.s.a. all other trademarks mentioned herein are property of their respective companies. ? 2009, microchip technology incorporated, printed in the u.s.a., all rights reserved. printed on recycled paper. note the following details of the code protection feature on microchip devices: ? microchip products meet the specification cont ained in their particular microchip data sheet. ? microchip believes that its family of products is one of the mo st secure families of its kind on the market today, when used i n the intended manner and under normal conditions. ? there are dishonest and possibly illegal methods used to breach the code protection feature. all of these methods, to our knowledge, require using the microchip produc ts in a manner outside the operating specifications contained in microchip?s data sheets. most likely, the person doing so is engaged in theft of intellectual property. ? microchip is willing to work with the customer who is concerned about the integrity of their code. ? neither microchip nor any other semiconductor manufacturer c an guarantee the security of their code. code protection does not mean that we are guaranteeing the product as ?unbreakable.? code protection is constantly evolving. we at microchip are co mmitted to continuously improvi ng the code protection features of our products. attempts to break microchip?s c ode protection feature may be a violation of the digital millennium copyright act. if such acts allow unauthorized access to your software or other copyrighted work, you may have a right to sue for relief under that act. microchip received iso/ts-16949:2002 certification for its worldwide headquarters, design and wafer fabrication facilities in chandler and tempe, arizona; gresham, oregon and design centers in california and india. the company?s quality system processes and procedures are for its pic ? mcus and dspic ? dscs, k ee l oq ? code hopping devices, serial eeproms, microperipherals, nonvolatile memory and analog products. in addition, microchip?s quality system for the design and manufacture of development systems is iso 9001:2000 certified.
? 2009 microchip technology inc. preliminary ds39937b-page 1 pic24f04ka201 family power management modes: ? run ? cpu, flash, sram and peripherals on ? doze ? cpu clock runs slower than peripherals ? idle ? cpu off, flash, sram and peripherals on ? sleep ? cpu, flash and peripherals off and sram on ? deep sleep ? cpu, flash, sram and most peripherals off ? run mode currents down to 8 a typical ? idle mode currents down to 2 a typical ? deep sleep mode currents down to 20 na typical ? watchdog timer 350 na, 1.8v typical high-performance cpu: ? modified harvard architecture ? up to 16 mips operation @ 32 mhz ? 8 mhz internal oscillator with 4x pll option and multiple divide options ? 17-bit by 17-bit single-cycle hardware multiplier ? 32-bit by 16-bit hardware divider ? 16-bit x 16-bit working register array ? c compiler optimized instruction set architecture peripheral features: ? serial communication modules: - spi, i 2 c? and uart modules ? three 16-bit timers/counters with programmable prescaler ? 16-bit capture inputs ? 16-bit compare/pwm output ? configurable open-drain outputs on digital i/o pins ? up to three external interrupt sources analog features: ? 10-bit, up to 9-channel analog-to-digital converter: - 500 ksps conversion rate - conversion available during sleep and idle ? dual analog comparators with programmable input/ output configuration ? charge time measurement unit (ctmu): - used for capacitance sensing - compatible with mtouch? capacitive sensing - time measurement, down to 1 ns resolution - delay/pulse generation, down to 1 ns resolution special microcontroller features: ? operating voltage range of 1.8v to 3.6v ? high-current sink/source (18 ma/18 ma) on all i/o pins ? flash program memory: - erase/write cycles: 10000 minimum - 40 years data retention minimum ? fail-safe clock monitor ? system frequency range declaration bits: - declaring the frequency range helps in optimizing the current consumption. ? flexible watchdog timer (wdt) with on-chip, low-power rc oscillator for reliable operation ? in-circuit serial programming? (icsp?) ? programmable high/low-voltage detect (hlvd) ? brown-out reset (bor): - standard bor with three programmable trip points; can be disabled in sleep ? extreme low-power dsbor for deep sleep, lpbor for all other modes pic24f device pins program memory (bytes) sram (bytes) timers 16-bit input capture output compare/ pwm uart/ irda ? i 2 c? 10-bit a/d (ch) comparators ctmu (ch) spi 04ka200 14 4k 512 3 1 1 1 1 1 7 2 7 04ka201 20 4k 512 3 1 1 1 1 1 9 2 9 14/20-pin general purpose, 16-bit flash microcontrollers with nanowatt xlp? technology
pic24f04ka201 family ds39937b-page 2 preliminary ? 2009 microchip technology inc. pin diagrams 14-pin pdip, tssop (1) 20-pin pdip, ssop, soic (1) pic24f04ka200 mclr /v pp /ra5 pgc2/an0/v ref +/cn2/ra0 pgd2/an1/v ref -/cn3/ra1 v dd v ss osci/clki/an4/c1inb/cn30/ra2 pgc3/sosco/an3/c2ina/t1ck/cn0/ra4 pgd3/sosci/an2/c2inb/hlvdin/cn1/rb4 osco/clko/an5/c1ina/cn29/ra3 1 2 3 4 5 6 7 14 13 12 11 10 9 8 refo/u1rx/ss1 /t2ck/t3ck/int0/ctpls/cn11/rb15 an10/cv ref /u1tx/sdi1/ocfa/c1out/int1/cted2/cn12/rb14 oc1/ic1/c2out/int2/cted1/cn8/ra6 sda1/u1bclk/u1rts /sdo1/cn21/rb9 scl1/u1cts /sck1/cn22/rb8 pic24f04ka201 mclr /v pp /ra5 osco/clko/an5/c1ina/cn29/ra3 pgc2/an0/v ref +/cn2/ra0 pgd2/an1/v ref -/cn3/ra1 v dd v ss an2/c2inb/cn4/rb0 u1tx/int0/cn23/rb7 pgc3/sosco/t1ck/cn0/ra4 pgd3/sosci/cn1/rb4 scl1/u1cts /cn22/rb8 osci/clki/an4/c1inb/cn30/ra2 u1rx/cn6/rb2 an3/c2ina/cn5/rb1 1 2 3 4 5 6 7 8 9 10 20 19 18 17 16 15 14 13 12 11 refo/ss1 /t2ck/t3ck/cn11/rb15 an10/cv ref /sdi1/ocfa/c1out/int1/cn12/rb14 an11/sdo1/ctpls/cn13/rb13 an12/hlvdin/sck1/cted2/cn14/rb12 sda1/u1bclk/u1rts /cn21/rb9 oc1/ic1/c2out/int2/cted1/cn8/ra6 note 1: all device pins have a maximum voltage of 3.6v and are not 5v tolerant.
? 2009 microchip technology inc. preliminary ds39937b-page 3 pic24f04ka201 family pin diagrams (continued) 20-pin qfn (1,2) 89 2 3 1 12 13 14 15 10 6 11 16 17 18 19 20 7 pic24f04ka201 5 4 mclr /v pp /ra5 pgc2/an0/v ref +/cn2/ra0 pgd2/an1/v ref -/cn3/ra1 v dd v ss an2/c2inb/cn4/rb0 pgc3/sosco/t1ck/cn0/ra4 pgd3/sosci/cn1/rb4 osco/clko/an5/c1ina/cn29/ra3 osci/clki/an4/c1inb/cn30/ra2 oc1/ic1/c2out/int2/cted1/cn8/ra6 u1tx/int0/cn23/rb7 an10/cv ref /sdi1/ocfa/c1out/int1/cn12/rb14 scl1/u1cts /cn22/rb8 u1rx/u1bclk/cn6/rb2 an3/c2ina/cn5/rb1 an11/sdo1/ctpls/cn13/rb13 an12/hlvdin/sck1/cted2/cn14/rb12 sda1/u1bclk/u1rts /cn21/rb9 refo/ss1 /t2ck/t3ck/cn11/rb15 note 1: connecting the bottom pad to vss is recommended. 2: all device pins have a maximum voltage of 3.6v and are not 5v tolerant.
pic24f04ka201 family ds39937b-page 4 preliminary ? 2009 microchip technology inc. table of contents 1.0 device overview ............................................................................................................. ............................................................. 7 2.0 guidelines for getting started with 16-bit microcontrollers ................................................................. ....................................... 15 3.0 cpu ........................................................................................................................ ................................................................... 19 4.0 memory organization ......................................................................................................... ........................................................ 25 5.0 flash program memory........................................................................................................ ...................................................... 43 6.0 resets ...................................................................................................................... .................................................................. 51 7.0 interrupt controller ........................................................................................................ ............................................................. 57 8.0 oscillator configuration ...................................... .............................................................. .......................................................... 81 9.0 power-saving features....................................................................................................... ....................................................... 91 10.0 i/o ports .................................................................................................................. ................................................................... 99 11.0 timer1 .................................................................................................................... ................................................................. 101 12.0 timer2/3 ................................................................................................................... ................................................................ 103 13.0 input capture.............................................................................................................. .............................................................. 109 14.0 output compare ............................................................................................................. .......................................................... 111 15.0 serial peripheral interface (spi).......................................................................................... ..................................................... 117 16.0 inter-integrated circuit (i 2 c?) ............................................................................................................................ ..................... 125 17.0 universal asynchronous receiver transmitter (uart) ......................................................................... .................................. 133 18.0 high/low-voltage detect (hlvd)............................................................................................. ................................................ 141 19.0 10-bit high-speed a/d converter ............................................................................................ ................................................ 143 20.0 comparator module.......................................................................................................... ........................................................ 153 21.0 comparator voltage reference............................................................................................... ................................................. 157 22.0 charge time measurement unit (ctmu) ........................................................................................ ........................................ 159 23.0 special features ........................................................................................................... ........................................................... 163 24.0 development support........................................................................................................ ....................................................... 173 25.0 instruction set summary .................................................................................................... ...................................................... 177 26.0 electrical characteristics ................................................................................................. ......................................................... 185 27.0 packaging information...................................................................................................... ........................................................ 205 appendix a: revision history................................................................................................... .......................................................... 213 index .......................................................................................................................... ........................................................................ 215 the microchip web site ......................................................................................................... ............................................................ 219 customer change notification service ........................................................................................... ................................................... 219 customer support ............................................................................................................... ............................................................... 219 reader response ................................................................................................................ .............................................................. 220 product identification system.................................................................................................. ........................................................... 221
? 2009 microchip technology inc. preliminary ds39937b-page 5 pic24f04ka201 family to our valued customers it is our intention to provide our valued customers with the best documentation possible to ensure successful use of your micro chip products. to this end, we will continue to improve our publications to better suit your needs. our publications will be refined and enhanced as new volumes and updates are introduced. if you have any questions or comments regar ding this publication, please contact the marketing communications department via e-mail at docerrors@microchip.com or fax the reader response form in the back of this data sheet to (480) 792-4150. we welcome your feedback. most current data sheet to obtain the most up-to-date version of this data s heet, please register at our worldwide web site at: http://www.microchip.com you can determine the version of a data sheet by examining its literature number found on the bottom outside corner of any page . the last character of the literature number is the vers ion number, (e.g., ds30000a is version a of document ds30000). errata an errata sheet, describing minor operational differences fr om the data sheet and recommended workarounds, may exist for curren t devices. as device/documentation issues become known to us, we will publish an errata sheet. the errata will specify the revisi on of silicon and revision of document to which it applies. to determine if an errata sheet exists for a particular device, please check with one of the following: ? microchip?s worldwide web site; http://www.microchip.com ? your local microchip sales office (see last page) when contacting a sales office, please specify which device, re vision of silicon and data sheet (include literature number) you are using. customer notification system register on our web site at www.microchip.com to receive the most current information on all of our products.
pic24f04ka201 family ds39937b-page 6 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 7 pic24f04ka201 family 1.0 device overview this document contains device-specific information for the following devices: ? pic24f04ka200 ? pic24f04ka201 the pic24f04ka201 family introduces a new line of extreme low-power microchip devices: a 16-bit micro- controller family with a broad peripheral feature set and enhanced computational performance. it also offers a new migration option for those high-performance appli- cations, which may be outgrowing their 8-bit platforms, but do not require the numerical processing power of a digital signal processor. 1.1 core features 1.1.1 16-bit architecture central to all pic24f devices is the 16-bit modified harvard architecture, first introduced with microchip?s dspic ? digital signal controllers. the pic24f cpu core offers a wide range of enhancements, such as: ? 16-bit data and 24-bit address paths with the ability to move information between data and memory spaces ? linear addressing of up to 12 mbytes (program space) and 64 kbytes (data) ? a 16-element working register array with built-in software stack support ? a 17 x 17 hardware multiplier with support for integer math ? hardware support for 32-bit by 16-bit division ? an instruction set that supports multiple addressing modes and is optimized for high-level languages, such as c ? operational performance up to 16 mips 1.1.2 power-saving technology the pic24f04ka200 and pic24f04ka201 devices incorporate a range of features that can significantly reduce power consumption during operation. key items include: ? on-the-fly clock switching: the device clock can be changed under software control to the timer1 source or the internal, low-power rc oscillator during operation, allowing users to incorporate power-saving ideas into their software designs. ? doze mode operation: when timing-sensitive applications, such as serial communications, require the uninterrupted operation of peripherals, the cpu clock speed can be selectively reduced, allowing incremental power savings without missing a beat. ? instruction-based power-saving modes: there are three instruction-based power-saving modes: - idle mode: the core is shut down while leaving the peripherals active. - sleep mode: the core and peripherals that require the system clock are shut down, leaving the peripherals that use their own clock, or the clock from other devices, active. - deep sleep mode: the core, peripherals (except dswdt), flash and sram are shut down. 1.1.3 oscillator options and features the pic24f04ka201 family offers five different oscillator options, allowing users a range of choices in developing application hardware. these include: ? two crystal modes using crystals or ceramic resonators. ? two external clock modes offering the option of a divide-by-2 clock output. ? two fast internal oscillators (frcs): one with a nominal 8 mhz output and the other with nominal 500 khz output. these outputs can also be divided under software control to provide clock speed as low as 31 khz or 2 khz. ? a phase locked loop (pll) frequency multiplier, available to the external oscillator modes and the 8 mhz frc oscillator, which allows clock speeds of up to 32 mhz. ? a separate internal rc oscillator (lprc) with a fixed 31 khz output, which provides a low-power option for timing-insensitive applications.
pic24f04ka201 family ds39937b-page 8 preliminary ? 2009 microchip technology inc. the internal oscillator block also provides a stable reference source for the fail-safe clock monitor (fscm). this option constantly monitors the main clock source against a reference signal provided by the internal oscillator and enables the controller to switch to the internal oscillator, allowing for continued low-speed operation or a safe application shutdown. 1.1.4 easy migration regardless of the memory size, all the devices share the same rich set of peripherals, allowing for a smooth migration path as applications grow and evolve. the consistent pinout scheme used throughout the entire family also helps in migrating to the next larger device. this is true when moving between devices with the same pin count, or even jumping from 14-pin to 20-pin devices. the pic24f16ka102 family is directly compatible for migration to larger program and data memory. the pic24f family is pin compatible with devices in the dspic33 family, and shares some compatibility with the pinout schema for pic18 and dspic30. this extends the ability of applications to grow from the relatively simple, to the powerful and complex. 1.2 other special features ? communications: the pic24f04ka201 family incorporates a range of serial communication peripherals to handle a range of application requirements. there is an i 2 c? module that supports both the master and slave modes of operation. it also comprises a uart with built-in irda ? encoders/decoders and an spi module. ? 10-bit a/d converter: this module incorporates programmable acquisition time, allowing for a channel to be selected and a conversion to be initiated without waiting for a sampling period, and faster sampling speed. the 16-deep result buffer can be used either in sleep to reduce power, or in active mode to improve throughput. ? charge time measurement unit (ctmu) interface: the pic24f04ka201 family includes the new ctmu interface module, which can be used for capacitive touch sensing using microchip?s mtouch? technology, proximity sensing and also for precision time measurement and pulse generation. 1.3 details on individual family members devices in the pic24f04ka201 family are available in 14-pin and 20-pin packages. the general block diagram for all devices is displayed in figure 1-1. the devices are different from each other in two ways: 1. number of adc channels (9 channels on 20-pin parts, 7 channels on 14-pin parts). 2. available i/o pins and ports (12 pins on two ports for 14-pin devices and 18 pins on two ports for 20-pin devices). all other features for devices in this family are identical; these are summarized in table 1-1. a list of the pin features available on the pic24f04ka201 family devices, sorted by function, is provided in table 1-2. 1.4 differences from pic24f16ka102 family the pic24f04ka201 family architecture is very similar to that of the pic24f16ka102 family. the pic24f04ka201 family is a subset of the pic24f16ka102 devices. the pic24f16ka102 family has the following additional features: ? larger program memory ? larger data memory ? crc module ? debugging capabilities through icsp? ? additional i/o on 20-pin devices (up to 24 i/o pins) ? data eeprom memory ? boot segment and general segments for program code (with available code protection) ? one additional uart (2 total) note: table 1-1 provides the pin location of individual peripheral features and not how they are multiplexed on the same pin. this information is provided in the pinout diagrams on pages 2 and 3 of the data sheet. multiplexed features are sorted by the priority given to a feature, with the highest priority peripheral being listed first.
? 2009 microchip technology inc. preliminary ds39937b-page 9 pic24f04ka201 family table 1-1: device features for the pic24f04ka201 family features pic24f04ka200 pic24f04ka201 operating frequency dc ? 32 mhz program memory (bytes) 4k program memory (instructions) 1408 data memory (bytes) 512 interrupt sources (soft vectors/nmi traps) 25 (21/4) i/o ports porta<6:0> portb<15:14, 9:8, 4> porta<6:0> portb<15:12, 9:7, 4, 2:0> total i/o pins 12 18 timers: total number (16-bit) 32-bit (from paired 16-bit timers) 3 1 input capture channels 1 output compare/pwm channels 1 input change notification interrupt 11 17 serial communications: uart spi (3-wire/4-wire) i 2 c? 1 1 1 10-bit analog-to-digital module (input channels) 7 9 analog comparators 2 resets (and delays) por, bor, reset instruction, mclr , wdt, illegal opcode, repeat instruction, hardware traps, configuration word mismatch (pwrt, ost, pll lock) instruction set 76 base instructions, multiple addressing mode variations packages 14-pin pdip/tssop 20-pin pdip/ssop/soic/qfn
pic24f04ka201 family ds39937b-page 10 preliminary ? 2009 microchip technology inc. figure 1-1: pic24f04ka201 family general block diagram instruction decode and control 16 pch pcl 16 program counter 16-bit alu 23 24 data bus inst register 16 divide support inst latch 16 ea mux read agu write agu 16 16 8 interrupt controller psv and table data access control block stack control logic repeat control logic data latch data ram address latch address latch program memory data latch 16 address bus literal data 23 control signals 16 16 16 x 16 w reg array multiplier 17x17 porta (1) ra<6:0> portb (1) rb<15:12, 9:7> note 1: all pins or features are not implemented on all device pinout confi gurations. see table 1-2 for i/o port pin descriptions. comparators timer2/3 timer1 ctmu ic1 adc 10-bit oc1/pwm spi1 i2c1 cn1-17 (1) uart1 osci/clki osco/clko v dd , timing generation v ss mclr power-up timer oscillator start-up timer power-on reset watchdog timer bor precision reference band gap frc/lprc oscillators dswdt hlvd refo rb<4, 2:0>
? 2009 microchip technology inc. preliminary ds39937b-page 11 pic24f04ka201 family table 1-2: pic24f04ka201 fa mily pinout descriptions function pin number i/o input buffer description 14-pin pdip/tssop/ soic 20-pin pdip/ssop/ soic 20-pin qfn an0 2 2 19 i ana a/d analog inputs an1 3 3 20 i ana an2 6 4 1 i ana an3 7 5 2 i ana an4 4 7 4 i ana an5 5 8 5 i ana an10 11 17 14 i ana an11 ? 16 13 i ana an12 ? 15 12 i ana u1bclk 9 13 10 o ? uart1 irda ? baud clock c1ina 5 8 5 i ana comparator 1 input a (positive input) c1inb 4 7 4 i ana comparator 1 input b (negative input option 1) c1out 11 17 14 o ? comparator 1 output c2ina 7 5 2 i ana comparator 2 input a (positive input) c2inb 6 4 1 i ana comparator 2 input b (negative input option 1) c2out 10 14 11 o ? comparator 2 output clki 4 7 4 i ana main clock input connection clko 5 8 5 o ? system clock output cn0 7 10 7 i st interrupt-on-change inputs cn1 6 9 6 i st cn2 2 2 19 i st cn3 3 3 20 i st cn4 ? 4 1 i st cn5 ? 5 2 i st cn6 ? 6 3 i st cn8 10 14 11 i st cn11 12 18 15 i st cn12 11 17 14 i st cn13 ? 16 13 i st cn14 ? 15 12 i st cn21 9 13 10 i st cn22 8 12 9 i st cn23 ? 11 8 i st cn29 5 8 5 i st cn30 4 7 4 i st cv ref 11 17 14 o ana comparator voltage reference output cted1 10 14 11 i st ctmu trigger edge input 1 cted2 11 15 12 i st ctmu trigger edge input 2 ctpls 12 16 13 o ? ctmu pulse output ic1 10 14 11 i st input capture 1 input int0 12 11 8 i st external interrupt inputs int1 11 17 14 i st int2 10 14 11 i st legend: st = schmitt trigger input buffer, ana = analog level input/output, i 2 c? = i 2 c/smbus input buffer
pic24f04ka201 family ds39937b-page 12 preliminary ? 2009 microchip technology inc. hlvdin 6 15 12 i ana hlvd voltage input mclr 1 1 18 i st master clear (device reset) input oc1 10 14 11 o ? output compare/pwm outputs ocfa 11 17 14 i ? output compare fault a osci 4 7 4 i ana main oscillator input connection osco 5 8 5 o ana main oscillator output connection pgc2 2 2 19 i/o st in-circuit debugger and icsp programming clock pgd2 3 3 20 i/o st in-circuit debugger and icsp programming data pgc3 7 10 7 i/o st in-circuit debugger and icsp programming clock pgd3 6 9 6 i/o st in-circuit debugger and icsp programming data ra0 2 2 19 i/o st porta digital i/o ra1 3 3 20 i/o st ra2 4 7 4 i/o st ra3 5 8 5 i/o st ra4 7 10 7 i/o st ra5 1 1 18 i/o st ra6 10 14 11 i/o st rb0 ? 4 1 i/o st portb digital i/o rb1 ? 5 2 i/o st rb2 ? 6 3 i/o st rb4 6 9 6 i/o st rb8 8 12 9 i/o st rb9 9 13 10 i/o st rb12 ? 15 12 i/o st rb13 ? 16 13 i/o st rb14 11 17 14 i/o st rb15 12 18 15 i/o st refo 12 18 15 o ? reference clock output sck1 8 15 12 i/o st spi1 serial clock input/output scl1 8 12 9 i/o i 2 c i2c1 synchronous serial clock input/output sda1 9 13 10 i/o i 2 c i2c1 data input/output sdi1 11 17 14 i st spi1 serial data input sdo1 9 16 13 o ? spi1 serial data output sosci 6 9 6 i ana secondary oscillator input sosco 7 10 7 o ana secondary oscillator output ss1 12 18 15 i/o st slave select input/frame select output (spi1) t1ck 7 10 7 i st timer1 clock t2ck 12 18 15 i st timer2 clock t3ck 12 18 15 i st timer3 clock u1cts 8 12 9 i st uart1 clear to send input u1rts 9 13 10 o ? uart1 request to send output u1rx 12 6 3 i st uart1 receive u1tx 11 11 8 o ? uart1 transmit output table 1-2: pic24f04ka201 family pinout descriptions (continued) function pin number i/o input buffer description 14-pin pdip/tssop/ soic 20-pin pdip/ssop/ soic 20-pin qfn legend: st = schmitt trigger input buffer, ana = analog level input/output, i 2 c? = i 2 c/smbus input buffer
? 2009 microchip technology inc. preliminary ds39937b-page 13 pic24f04ka201 family v dd 14 20 17 p ? positive supply for peripheral digital logic and i/o pins v pp 1 1 18 p ? programming mode entry voltage v ref - 3 3 20 i ana a/d and comparator reference voltage (low) input v ref + 2 2 19 i ana a/d and comparator reference voltage (high) input v ss 13 19 16 p ? ground reference for logic and i/o pin table 1-2: pic24f04ka201 family pinout descriptions (continued) function pin number i/o input buffer description 14-pin pdip/tssop/ soic 20-pin pdip/ssop/ soic 20-pin qfn legend: st = schmitt trigger input buffer, ana = analog level input/output, i 2 c? = i 2 c/smbus input buffer
pic24f04ka201 family ds39937b-page 14 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 15 pic24f04ka201 family 2.0 guidelines for getting started with 16-bit microcontrollers 2.1 basic connection requirements getting started with the pic24fxxxx of 16-bit microcontrollers requires attention to a minimal set of device pin connections before proceeding with development. the following pins must always be connected: ?all v dd and v ss pins (see section 2.2 ?power supply pins? ) ?all av dd and av ss pins, regardless of whether or not the analog device features are used (see section 2.2 ?power supply pins? ) ?m clr pin (see section 2.3 ?master clear (mclr) pin? ) ? envreg/disvreg and v cap /v ddcore pins (pic24f devices only) (see section 2.4 ?voltage regulator pins (envreg/disvreg and v cap /v ddcore )? ) these pins must also be connected if they are being used in the end application: ? pgecx/pgedx pins used for in-circuit serial programming? (icsp?) and debugging purposes (see section 2.5 ?icsp pins? ) ? osci and osco pins when an external oscillator source is used (see section 2.6 ?external oscillator pins? ) additionally, the following pins may be required: ?v ref +/v ref - pins used when external voltage reference for analog modules is implemented the minimum mandatory connections are shown in figure 2-1. figure 2-1: recommended minimum connections note: the av dd and av ss pins must always be connected, regardless of whether any of the analog modules are being used. pic24fxxxx v dd v ss v dd v ss v ss v dd av dd av ss v dd v ss c1 r1 v dd mclr v cap /v ddcore r2 (en/dis)vreg (1) c7 c2 (2) c3 (2) c4 (2) c5 (2) c6 (2) key (all values are recommendations): c1 through c6: 0.1 f, 20v ceramic c7: 10 f, 6.3v or greater, tantalum or ceramic r1: 10 k ? r2: 100 ? to 470 ? note 1: see section 2.4 ?voltage regulator pins (envreg/disvreg and v cap /v ddcore )? for explanation of envreg/disvreg pin connections. 2: the example shown is for a pic24f device with five v dd /v ss and av dd /av ss pairs. other devices may have more or less pairs; adjust the number of decoupling capacitors appropriately. (1)
pic24f04ka201 family ds39937b-page 16 preliminary ? 2009 microchip technology inc. 2.2 power supply pins 2.2.1 decoupling capacitors the use of decoupling capacitors on every pair of power supply pins, such as v dd , v ss , av dd and av ss , is required. consider the following criteria when using decoupling capacitors: ? value and type of capacitor: a 0.1 f (100 nf), 10-20v capacitor is recommended. the capacitor should be a low-esr device with a resonance frequency in the range of 200 mhz and higher. ceramic capacitors are recommended. ? placement on the printed circuit board: the decoupling capacitors should be placed as close to the pins as possible. it is recommended to place the capacitors on the same side of the board as the device. if space is constricted, the capacitor can be placed on another layer on the pcb using a via; however, ensure that the trace length from the pin to the capacitor is no greater than 0.25 inch (6 mm). ? handling high-frequency noise: if the board is experiencing high-frequency noise (upward of tens of mhz), add a second ceramic type capaci- tor in parallel to the above described decoupling capacitor. the value of the second capacitor can be in the range of 0.01 f to 0.001 f. place this second capacitor next to each primary decoupling capacitor. in high-speed circuit designs, consider implementing a decade pair of capacitances as close to the power and ground pins as possible (e.g., 0.1 f in parallel with 0.001 f). ? maximizing performance: on the board layout from the power supply circuit, run the power and return traces to the decoupling capacitors first, and then to the device pins. this ensures that the decoupling capacitors are first in the power chain. equally important is to keep the trace length between the capacitor and the power pins to a minimum, thereby reducing pcb trace inductance. 2.2.2 tank capacitors on boards with power traces running longer than six inches in length, it is suggested to use a tank capacitor for integrated circuits including microcontrollers to supply a local power source. the value of the tank capacitor should be determined based on the trace resistance that connects the power supply source to the device and the maximum current drawn by the device in the application. in other words, select the tank capacitor so that it meets the acceptable voltage sag at the device. typical values range from 4.7 f to 47 f. 2.3 master clear (mclr ) pin the mclr pin provides two specific device functions: device reset, and device programming and debugging. if programming and debugging are not required in the end application, a direct connection to v dd may be all that is required. the addition of other components, to help increase the application?s resistance to spurious resets from voltage sags, may be beneficial. a typical configuration is shown in figure 2-1. other circuit designs may be implemented depending on the application?s requirements. during programming and debugging, the resistance and capacitance that can be added to the pin must be considered. device progr ammers and debuggers drive the mclr pin. consequently, specific voltage levels (v ih and v il ) and fast signal transitions must not be adversely affected. therefor e, specific values of r1 and c1 will need to be adjusted based on the application and pcb requirements. for example, it is recommended that the capacitor, c1, be isolated from the mclr pin during programming and debugging operations by using a jumper (figure 2-2). the jumper is replaced for normal run-time operations. any components associated with the mclr pin should be placed within 0.25 inch (6 mm) of the pin. figure 2-2: example of mclr pin connections note 1: r1 10 k is recommended. a suggested starting value is 10 k . ensure that the mclr pin v ih and v il specifications are met. 2: r2 470 will limit any current flowing into mclr from the external capacitor, c, in the event of mclr pin breakdown, due to electrostatic discharge (esd) or electrical overstress (eos). ensure that the mclr pin v ih and v il specifications are met. c1 r2 r1 v dd mclr pic24fxxxx jp
? 2009 microchip technology inc. preliminary ds39937b-page 17 pic24f04ka201 family 2.4 voltage regulator pins (envreg/disvreg and v cap /v ddcore ) the on-chip voltage regulator enable/disable pin (envreg or disvreg, depending on the device family) must always be connected directly to either a supply voltage or to ground. the particular connection is determined by whether or not the regulator is to be used: ? for envreg, tie to v dd to enable the regulator or to ground to disable the regulator ? for disvreg, tie to ground to enable the regulator or to v dd to disable the regulator when the regulator is enabled, a low-esr (<5 ? ) capacitor is required on the v cap /v ddcore pin to stabilize the voltage regulator output voltage. the v cap /v ddcore pin must not be connected to v dd and must use a capacitor of 10 f connected to ground. the type can be ceramic or tantalum. a suitable example is the murata grm21bf50j106ze01 (10 f, 6.3v) or equivalent. designers may use figure 2-3 to evaluate esr equivalence of candidate devices. the placement of this capacitor should be close to v cap /v ddcore . it is recommended that the trace length not exceed 0.25 inch (6 mm). refer to section 26.0 ?electrical characteristics? for additional information. when the regulator is disabled, the v cap /v ddcore pin must be tied to a voltage supply at the v ddcore level. refer to section 26.0 ?electrical characteristics? for information on v dd and v ddcore . figure 2-3: frequency vs. esr performance for suggested v cap 2.5 icsp pins the pgecx and pgedx pins are used for in-circuit serial programming (icsp) and debugging purposes. it is recommended to keep the trace length between the icsp connector and the icsp pins on the device as short as possible. if the icsp connector is expected to experience an esd event, a series resistor is recom- mended, with the value in the range of a few tens of ohms, not to exceed 100 ? . pull-up resistors, series diodes and capacitors on the pgecx and pgedx pins are not recommended as they will interfere with the programmer/debugger communi- cations to the device. if such discrete components are an application requirement, they should be removed from the circuit during programming and debugging. alternatively, refer to the ac/dc characteristics and timing requirements information in the respective device flash programming specification for information on capacitive loading limits and pin input voltage high (v ih ) and input low (v il ) requirements. for device emulation, ensure that the ?communication channel select? (i.e., pgecx/pgedx pins) programmed into the device matches the physical connections for the icsp to the mplab ? icd 2, mplab icd 3 or real ice? emulator. for more information on the icd 2, icd 3 and real ice emulator connection requirements, refer to the following documents that are available on the microchip web site. ? ?mplab ? icd 2 in-circuit debugger user?s guide? (ds51331) ? ?using mplab ? icd 2? (poster) (ds51265) ? ?mplab ? icd 2 design advisory? (ds51566) ? ?using mplab ? icd 3? (poster) (ds51765) ? ?mplab ? icd 3 design advisory? (ds51764) ? ?mplab ? real ice? in-circuit emulator user?s guide? (ds51616) ? ?using mplab ? real ice? in-circuit emulator? (poster) (ds51749) note: this section applies only to pic24f devices with an on-chip voltage regulator. 10 1 0.1 0.01 0.001 0.01 0.1 1 10 100 1000 10,000 frequency (mhz) esr ( ) note: data for murata grm21bf50j106ze01 shown. measurements at 25c, 0v dc bias.
pic24f04ka201 family ds39937b-page 18 preliminary ? 2009 microchip technology inc. 2.6 external oscillator pins many microcontrollers have options for at least two oscillators: a high-frequency primary oscillator and a low-frequency secondary oscillator (refer to section 8.0 ?oscillator configuration? for details). the oscillator circuit should be placed on the same side of the board as the device. place the oscillator circuit close to the respective oscillator pins with no more than 0.5 inch (12 mm) between the circuit components and the pins. the load capacitors should be placed next to the oscillator itself, on the same side of the board. use a grounded copper pour around the oscillator circuit to isolate it from surrounding circuits. the grounded copper pour should be routed directly to the mcu ground. do not run any signal traces or power traces inside the ground pour. also, if using a two-sided board, avoid any traces on the other side of the board where the crystal is placed. a suggested layout is shown in figure 2-4. for additional information and design guidance on oscillator circuits, please refer to these microchip application notes, available at the corporate web site (www.microchip.com): ? an826, ? crystal oscillator basics and crystal selection for rfpic? and picmicro ? devices? ? an849, ?basic picmicro ? oscillator design? ? an943, ?practical picmicro ? oscillator analysis and design? ? an949, ?making your oscillator work? figure 2-4: suggested placement of the oscillator circuit 2.7 configuration of analog and digital pins during icsp operations if the mplab icd 2, icd 3 or real ice emulator is selected as a debugger, it automatically initializes all of the a/d input pins (anx) as ?digital? pins by setting all bits in the ad1pcfgl register. the bits in this register that correspond to the a/d pins that are initialized by the mplab icd 2, icd 3 or real ice emulator must not be cleared by the user application firmware; otherwise, communication errors will result between the debugger and the device. if your application needs to use certain a/d pins as analog input pins during the debug session, the user application must clear the corresponding bits in the ad1pcfgl register during initialization of the adc module. when the mplab icd 2, icd 3 or real ice emulator is used as a programmer, the user application firmware must correctly configure the ad1pcfgl register. automatic initialization of this register is only done during debugger operation. failure to correctly configure the register(s) will result in all a/d pins being recognized as analog input pins, resulting in the port value being read as a logic ? 0 ?, which may affect user application functionality. 2.8 unused i/os unused i/o pins should be configured as outputs and driven to a logic low state. alternatively, connect a 1 k ? to 10 k ? resistor to v ss on unused pins and drive the output to logic low. 13 main oscillator guard ring guard trace secondary oscillator 14 15 16 17 18 19 20
? 2009 microchip technology inc. preliminary ds39937b-page 19 pic24f04ka201 family 3.0 cpu the pic24f cpu has a 16-bit (data) modified harvard architecture with an enhanced instruction set and a 24-bit instruction word with a variable length opcode field. the program counter (pc) is 23 bits wide and addresses up to 4m instructions of user program memory space. a single-cycle instruction prefetch mechanism is used to help maintain throughput and provides predictable execution. all instructions execute in a single cycle, with the exception of instructions that change the program flow, the double-word move ( mov.d ) instruction and the table instructions. overhead-free program loop constructs are supported using the repeat instructions, which are interruptible at any point. pic24f devices have sixteen, 16-bit working registers in the programmer?s model. each of the working registers can act as a data, address or address offset register. the 16 th working register (w15) operates as a software stack pointer (ssp) for interrupts and calls. the upper 32 kbytes of the data space memory map can optionally be mapped into program space at any 16k word boundary of program memory defined by the 8-bit program space visibility page address (psvpag) register. the program to data space mapping feature lets any instruction access program space as if it were data space. the instruction set architecture (isa) has been significantly enhanced beyond that of the pic18, but maintains an acceptable level of backward compatibility. all pic18 instructions and addressing modes are supported, either directly, or through simple macros. many of the isa enhancements have been driven by compiler efficiency needs. the core supports inherent (no operand), relative, literal, memory direct and three groups of addressing modes. all modes support register direct and various register indirect modes. each group offers up to seven addressing modes. instructions are associated with predefined addressing modes depending upon their functional requirements. for most instructions, the core is capable of executing a data (or program data) memory read, a working register (data) read, a data memory write and a program (instruction) memory read per instruction cycle. as a result, three parameter instructions can be supported, allowing trinary operations (that is, a + b = c) to be executed in a single cycle. a high-speed, 17-bit by 17-bit multiplier has been included to significantly enhance the core arithmetic capability and throughput. the multiplier supports signed, unsigned and mixed mode, 16-bit by 16-bit or 8-bit by 8-bit integer multiplication. all multiply instructions execute in a single cycle. the 16-bit alu has been enhanced with integer divide assist hardware that supports an iterative non-restoring divide algorithm. it operates in conjunction with the repeat instruction looping mechanism and a selection of iterative divide instructions to support 32-bit (or 16-bit), divided by 16-bit integer signed and unsigned division. all divide operations require 19 cycles to complete but are interruptible at any cycle boundary. the pic24f has a vectored exception scheme with up to eight sources of non-maskable traps and up to 118 interrupt sources. each interrupt source can be assigned to one of seven priority levels. a block diagram of the cpu is illustrated in figure 3-1. 3.1 programmer?s model figure 3-2 displays the programmer?s model for the pic24f. all registers in the programmer?s model are memory mapped and can be manipulated directly by instructions. table 3-1 provides a description of each register. all registers associated with the programmer?s model are memory mapped. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the cpu, refer to the ?pic24f family reference manual? , section 2. ?cpu? (ds39703).
pic24f04ka201 family ds39937b-page 20 preliminary ? 2009 microchip technology inc. figure 3-1: pic24f cp u core block diagram table 3-1: cpu core registers instruction decode and control pch pcl 16 program counter 16-bit alu 23 23 24 23 data bus instruction reg 16 16 x 16 w register array divide support rom latch 16 ea mux ragu wagu 16 16 8 interrupt controller psv and table data access control block stack control logic loop control logic data latch data ram address latch control signals to various blocks program memory data latch address bus 16 literal data 16 16 hardware multiplier 16 to peripheral modules address latch register(s) name description w0 through w15 working register array pc 23-bit program counter sr alu status register splim stack pointer limit value register tblpag table memory page address register psvpag program space visibility page address register rcount repeat loop counter register corcon cpu control register
? 2009 microchip technology inc. preliminary ds39937b-page 21 pic24f04ka201 family figure 3-2: programmer?s model novz c tblpag 22 0 7 0 0 15 program counter table memory page alu status register (sr) working/address registers w0 (wreg) w1 w2 w3 w4 w5 w6 w7 w8 w9 w10 w11 w12 w13 frame pointer stack pointer psvpag 7 0 program space visibility ra 0 rcount 15 0 repeat loop counter splim stack pointer limit srl registers or bits shadowed for push.s and pop.s instructions. 0 0 page address register 15 0 cpu control register (corcon) srh w14 w15 dc ipl 210 ?? ? ? ? ? ? ipl3 psv ???????????? ?? pc divider working registers multiplier registers 15 0 value register address register register
pic24f04ka201 family ds39937b-page 22 preliminary ? 2009 microchip technology inc. 3.2 cpu control registers register 3-1: sr: alu status register u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0, hsc ? ? ? ? ? ? ?dc bit 15 bit 8 r/w-0, hsc (1) r/w-0, hsc (1) r/w-0, hsc (1) r-0, hsc r/w-0, hsc r/w-0, hsc r/w-0, hsc r/w-0, hsc ipl2 (2) ipl1 (2) ipl0 (2) ra n ov z c bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 dc: alu half carry/borrow bit 1 = a carry-out from the 4 th low-order bit (for byte-sized data) or 8 th low-order bit (for word-sized data) of the result occurred 0 = no carry-out from the 4 th or 8 th low-order bit of the result has occurred bit 7-5 ipl<2:0>: cpu interrupt priority level status bits (1,2) 111 = cpu interrupt priority level is 7 (15); user interrupts disabled 110 = cpu interrupt priority level is 6 (14) 101 = cpu interrupt priority level is 5 (13) 100 = cpu interrupt priority level is 4 (12) 011 = cpu interrupt priority level is 3 (11) 010 = cpu interrupt priority level is 2 (10) 001 = cpu interrupt priority level is 1 (9) 000 = cpu interrupt priority level is 0 (8) bit 4 ra: repeat loop active bit 1 = repeat loop in progress 0 = repeat loop not in progress bit 3 n: alu negative bit 1 = result was negative 0 = result was non-negative (zero or positive) bit 2 ov: alu overflow bit 1 = overflow occurred for signed (2?s complement) arithmetic in this arithmetic operation 0 = no overflow has occurred bit 1 z: alu zero bit 1 = an operation, which effects the z bit, has set it at some time in the past 0 = the most recent operation, which effects the z bit, has cleared it (i.e., a non-zero result) bit 0 c: alu carry/borrow bit 1 = a carry-out from the most significant bit (msb) of the result occurred 0 = no carry-out from the most significant bit (msb) of the result occurred note 1: the ipl status bits are read-only when nstdis (intcon1<15>) = 1 . 2: the ipl status bits are concatenated with the ipl3 bit (corcon<3>) to form the cpu interrupt priority level (ipl). the value in parentheses indicates the ipl when ipl3 = 1 .
? 2009 microchip technology inc. preliminary ds39937b-page 23 pic24f04ka201 family 3.3 arithmetic logic unit (alu) the pic24f alu is 16 bits wide and is capable of addition, subtraction, bit shifts and logic operations. unless otherwise mentioned, arithmetic operations are 2?s complement in nature. depending on the operation, the alu may affect the values of the carry (c), zero (z), negative (n), overflow (ov) and digit carry (dc) status bits in the sr register. the c and dc status bits operate as borrow and digit borrow bits, respectively, for subtraction operations. the alu can perform 8-bit or 16-bit operations, depending on the mode of the instruction that is used. data for the alu operation can come from the w register array, or data memory, depending on the addressing mode of the instruction. likewise, output data from the alu can be written to the w register array or a data memory location. the pic24f cpu incorporates hardware support for both multiplication and division. this includes a dedicated hardware multiplier and support hardware division for 16-bit divisor. 3.3.1 multiplier the alu contains a high-speed, 17-bit x 17-bit multiplier. it supports unsigned, signed or mixed sign operation in several multiplication modes: ? 16-bit x 16-bit signed ? 16-bit x 16-bit unsigned ? 16-bit signed x 5-bit (literal) unsigned ? 16-bit unsigned x 16-bit unsigned ? 16-bit unsigned x 5-bit (literal) unsigned ? 16-bit unsigned x 16-bit signed ? 8-bit unsigned x 8-bit unsigned register 3-2: corcon: cpu control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 r/c-0, hsc r/w-0 u-0 u-0 ? ? ? ?ipl3 (1) psv ? ? bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-4 unimplemented: read as ? 0 ? bit 3 ipl3: cpu interrupt priority level status bit (1) 1 = cpu interrupt priority level is greater than 7 0 = cpu interrupt priority level is 7 or less bit 2 psv: program space visibility in data space enable bit 1 = program space visible in data space 0 = program space not visible in data space bit 1-0 unimplemented: read as ? 0 ? note 1: user interrupts are disabled when ipl3 = 1 .
pic24f04ka201 family ds39937b-page 24 preliminary ? 2009 microchip technology inc. 3.3.2 divider the divide block supports 32-bit/16-bit and 16-bit/16-bit signed and unsigned integer divide operations with the following data sizes: 1. 32-bit signed/16-bit signed divide 2. 32-bit unsigned/16-bit unsigned divide 3. 16-bit signed/16-bit signed divide 4. 16-bit unsigned/16-bit unsigned divide the quotient for all divide instructions ends up in w0 and the remainder in w1. sixteen-bit signed and unsigned div instructions can specify any w register for both the 16-bit divisor (wn), and any w register (aligned) pair (w(m + 1):wm) for the 32-bit dividend. the divide algorithm takes one cycle per bit of divisor, so both 32-bit/16-bit and 16-bit/16-bit instructions take the same number of cycles to execute. 3.3.3 multi-bit shift support the pic24f alu supports both single bit and single-cycle, multi-bit arithmetic and logic shifts. multi-bit shifts are implemented using a shifter block, capable of performing up to a 15-bit arithmetic right shift, or up to a 15-bit left shift, in a single cycle. all multi-bit shift instructions only support register direct addressing for both the operand source and result destination. a full summary of instructions that use the shift operation is provided below in table 3-2. table 3-2: instructions that use the si ngle and multi-bit shift operation instruction description asr arithmetic shift right source register by one or more bits. sl shift left source register by one or more bits. lsr logical shift right source register by one or more bits.
? 2009 microchip technology inc. preliminary ds39937b-page 25 pic24f04ka201 family 4.0 memory organization as with harvard architecture devices, the pic24f microcontrollers feature separate program and data memory space and busing. this architecture also allows the direct access of program memory from the data space during code execution. 4.1 program address space the program address memory space of the pic24f devices is 4m instructions. the space is addressable by a 24-bit value derived from either the 23-bit program counter (pc) during program ex ecution, or from a table operation or data space remapping, as described in section 4.3 ?interfacing program and data memory spaces? . the user access to the program memory space is restricted to the lower half of the address range (000000h to 7fffffh). the exception is the use of tblrd/tblwt operations, which use tblpag<7> to permit access to the configuration bits and device id sections of the configuration memory space. the memory map for the pic24f04ka201 family of devices is displayed in figure 4-1. figure 4-1: program space memory map for pic24f04ka201 family devices configuration memory space user memory space note: memory areas are not displayed to scale. reset address devid (2) goto instruction reserved reserved interrupt vector table pic24f04ka200/201 device config registers reserved unimplemented read ? 0 ? flash program memory (1408 instructions)
pic24f04ka201 family ds39937b-page 26 preliminary ? 2009 microchip technology inc. 4.1.1 program memory organization the program memory space is organized in word-addressable blocks. although it is treated as 24 bits wide, it is more appropriate to think of each address of the program memory as a lower and upper word, with the upper byte of the upper word being unimplemented. the lower word always has an even address, while the upper word has an odd address (figure 4-2). program memory addresses are always word-aligned on the lower word, and addresses are incremented or decremented by two during code execution. this arrangement also provides compatibility with data memory space addressing and makes it possible to access data in the program memory space. 4.1.2 hard memory vectors all pic24f devices reserve the addresses between 00000h and 000200h for hard coded program execution vectors. a hardware reset vector is provided to redirect code execution from the default value of the pc on device reset to the actual start of code. a goto instruction is programmed by the user at 000000h with the actual address for the start of code at 000002h. pic24f devices also have two interrupt vector tables, located from 000004h to 0000ffh and 000104h to 0001ffh. these vector tables allow each of the many device interrupt sources to be handled by separate isrs. section 7.1 ?interrupt vector (ivt) table? discusses the interrupt vector tables more in detail. 4.1.3 device configuration words table 4-1 provides the addresses of the device config- uration words for the pic24f04ka201 family. their location in the memory map is displayed in figure 4-1. refer to section 23.1 ?configuration bits? for more information on device configuration words. table 4-1: device configuration words for pic24f04ka201 family devices figure 4-2: program memory organization configuration word configuration word addresses fbs f80000 fgs f80004 foscsel f80006 fosc f80008 fwdt f8000a fpor f8000c ficd f8000e fds f80010 0 8 16 pc address 000000h 000002h 000004h 000006h 23 00000000 00000000 00000000 00000000 program memory ?phantom? byte (read as ? 0 ?) least significant word most significant word instruction width 000001h 000003h 000005h 000007h msw address (lsw address)
? 2009 microchip technology inc. preliminary ds39937b-page 27 pic24f04ka201 family 4.2 data address space the pic24f core has a separate, 16-bit wide data memory space, addressable as a single linear range. the data space is accessed using two address generation units (agus), one each for read and write operations. the data space memory map is displayed in figure 4-3. all effective addresses (eas) in the data memory space are 16 bits wide and point to bytes within the data space. this gives a data space address range of 64 kbytes or 32k words. the lower half of the data memory space (that is, when ea<15> = 0 ) is used for implemented memory addresses, while the upper half (ea<15> = 1 ) is reserved for the program space visibility (psv) area (see section 4.3.3 ?reading data from program memory using program space visibility? ). pic24f04ka201 family devices implement a total of 768 words of data memory. should an ea point to a location outside of this area, an all zero word or byte will be returned. 4.2.1 data space width the data memory space is organized in byte-addressable, 16-bit wide blocks. data is aligned in data memory and registers as 16-bit words, but all the data space eas resolve to bytes. the least significant bytes (lsbs) of each word have even addresses, while the most significant bytes (msbs) have odd addresses. figure 4-3: data space memory map for pic24f04ka201 family devices 0000h 07feh fffeh lsb address lsb msb msb address 0001h 07ffh 0dffh ffffh 8001h 8000h 7fffh 0801h 0800h near 09feh sfr sfr space data ram 7fffh program space visibility area note: data memory areas are not shown to scale. 1ffeh 1fff space data space implemented data ram unimplemented read as ? 0 ?
pic24f04ka201 family ds39937b-page 28 preliminary ? 2009 microchip technology inc. 4.2.2 data memory organization and alignment to maintain backward compatibility with pic ? devices and improve data space memory usage efficiency, the pic24f instruction set supports both word and byte operations. as a consequence of byte accessibility, all ea calculations are internally scaled to step through word-aligned memory. for example, the core recog- nizes that post-modified register indirect addressing mode [ws++] will result in a value of ws + 1 for byte operations and ws + 2 for word operations. data byte reads will read the complete word, which contains the byte, using the lsb of any ea to determine which byte to select. the selected byte is placed onto the lsb of the data path. that is, the data memory and the registers are organized as two parallel, byte-wide entities with shared (word) address decode but separate write lines. data byte writes only write to the corresponding side of the array or register, which matches the byte address. all word accesses must be aligned to an even address. misaligned word data fetches are not supported, so care must be taken when mixing byte and word operations, or translating from 8-bit mcu code. if a mis- aligned read or write is attempted, an address error trap will be generated. if the error occurred on a read, the instruction underway is completed; if it occurred on a write, the instruction will be executed, but the write will not occur. in either case, a trap is then executed, allowing the system and/or user to examine the machine state prior to execution of the address fault. all byte loads into any w register are loaded into the lsb. the msb is not modified. a sign-extend instruction ( se ) is provided to allow the users to translate 8-bit signed data to 16-bit signed values. alternatively, for 16-bit unsigned data, users can clear the msb of any w register by executing a zero-extend ( ze ) instruction on the appropriate address. although most instructions are capable of operating on word or byte data sizes, it should be noted that some instructions operate only on words. 4.2.3 near data space the 8-kbyte area between 0000h and 1fffh is referred to as the near data space. locations in this space are directly addressable via a 13-bit absolute address field within all memory direct instructions. the remainder of the data space is addressable indirectly. additionally, the whole data space is addressable using mov instructions, which support memory direct addressing (mda) with a 16-bit address field. for pic24f04ka201 family devices, the entire implemented data memory lies in near data space (nds). 4.2.4 sfr space the first 2 kbytes of the near data space, from 0000h to 07ffh, are primarily occupied with special function registers (sfrs). these are used by the pic24f core and peripheral modules for controlling the operation of the device. sfrs are distributed among the modules that they control and are generally grouped together by that module. much of the sfr space contains unused addresses; these are read as ? 0 ?. the sfr space, where the sfrs are actually implemented, is provided in table 4-2. each implemented area indicates a 32-byte region where at least one address is implemented as an sfr. a complete listing of implemented sfrs, including their addresses, is provided in table 4-3 through table 4-21. table 4-2: implemented regions of sfr data space sfr space address xx00 xx20 xx40 xx60 xx80 xxa0 xxc0 xxe0 000h core icn interrupts ? 100h timers capture ?compare ? ? ? 200h i 2 c? uart spi ? ?i/o 300h adc/cmtu ? ? ? ? ? ? 400h ? ? ? ? ? ? ? ? 500h ? ? ? ? ? ? ? ? 600h ?comp ? ? ? 700h ? ? system/ds/hlvd nvm/pmd ? ? ? ? legend: ? = no implemented sfrs in this block.
? 2009 microchip technology inc. preliminary ds39937b-page 29 pic24f04ka201 family table 4-3: cpu core registers map file name addrbit 15bit 14bit 13bit 12bit 11bit 10bit 9bit 8bit 7bit 6bit 5bit 4bit 3bit 2bit 1bit 0 all resets wreg0 0000 working register 0 0000 wreg1 0002 working register 1 0000 wreg2 0004 working register 2 0000 wreg3 0006 working register 3 0000 wreg4 0008 working register 4 0000 wreg5 000a working register 5 0000 wreg6 000c working register 6 0000 wreg7 000e working register 7 0000 wreg8 0010 working register 8 0000 wreg9 0012 working register 9 0000 wreg10 0014 working register 10 0000 wreg11 0016 working register 11 0000 wreg12 0018 working register 12 0000 wreg13 001a working register 13 0000 wreg14 001c working register 14 0000 wreg15 001e working register 15 0800 splim 0020 stack pointer limit value register xxxx pcl 002e program counter low byte register 0000 pch 0030 ? ? ? ? ? ? ? ? program counter register high byte 0000 tblpag 0032 ? ? ? ? ? ? ? ? table memory page address register 0000 psvpag 0034 ? ? ? ? ? ? ? ? program space visibility page address register 0000 rcount 0036 repeat loop counter register xxxx sr 0042 ? ? ? ? ? ? ? dc ipl2 ipl1 ipl0 ra n ov z c 0000 corcon 0044 ? ? ? ? ? ? ? ? ? ? ? ? ipl3 psv ? ? 0000 disicnt 0052 ? ? disable interrupts counter register xxxx legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
pic24f04ka201 family ds39937b-page 30 preliminary ? 2009 microchip technology inc. table 4-4: icn register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets cnen1 0060 ? cn14ie (1) cn13ie (1) cn12ie cn11ie ? ? cn8ie ? cn6ie (1) cn5ie (1) cn4ie (1) cn3ie cn2ie cn1ie cn0ie 0000 cnen2 0062 ? cn30ie cn29ie ? ? ? ? ?cn23ie (1) cn22ie cn21ie ? ? ? ? ? 0000 cnpu1 0068 ?cn14pue (1) cn13pue (1) cn12pue cn11pue ? ?cn8pue ? cn6pue (1) cn5pue (1) cn4pue (1) cn3pue cn2pue cn1pue cn0pue 0000 cnpu2 006a ? cn30pue cn29pue ? ? ? ? ? cn23pue (1) cn22pue cn21pue ? ? ? ? ? 0000 cnpd1 0070 ?cn14pde (1) cn13pde (1) cn12pde cn11pde ? ?cn8pde ? cn6pde (1) cn5pde (1) cn4pde (1) cn3pde cn2pde cn1pde cn0pde 0000 cnpd2 0072 ? cn30pde cn29pde ? ? ? ? ? cn23pde (1) cn22pde cn21pde ? ? ? ? ? 0000 legend: ? = unimplemented, read as ?0?. reset values are shown in hexadecimal. note 1: these bits are not implemented on 14-pin devices. table 4-5: interrupt controller register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets intcon1 0080 nstdis ? ? ? ? ? ? ? ? ? ? matherr addrerr stkerr oscfail ? 0000 intcon2 0082 altivt disi ? ? ? ? ? ? ? ? ? ? ? int2ep int1ep int0ep 0000 ifs0 0084 nvmif ? ad1if u1txif u1rxif spi1if spf1if t3if t2if ? ? ? t1if oc1if ic1if int0if 0000 ifs1 0086 ? ?int2if ? ? ? ? ? ? ? ? int1if cnif cmif mi2c1if si2c1if 0000 ifs3 008a ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0000 ifs4 008c ? ?ctmuif ? ? ? ?hlvdif ? ? ? ? ? ?u1erif ? 0000 iec0 0094 nvmie ? ad1ie u1txie u1rxie spi1ie spf1ie t3ie t2ie ? ? ? t1ie oc1ie ic1ie int0ie 0000 iec1 0096 ? ?int2ie ? ? ? ? ? ? ? ? int1ie cnie cmie mi2c1ie si2c1ie 0000 iec3 009a ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 0000 iec4 009c ? ?ctmuie ? ? ? ?hlvdie ? ? ? ? ? ?u1erie ? 0000 ipc0 00a4 ? t1ip2 t1ip1 t1ip0 ? oc1ip2 oc1ip1 oc1ip0 ? ic1ip2 ic1ip1 ic1ip0 ? int0ip2 int0ip1 int0ip0 4444 ipc1 00a6 ? t2ip2 t2ip1 t2ip0 ? ? ? ? ? ? ? ? ? ? ? ? 4444 ipc2 00a8 ? u1rxip2 u1rxip1 u1rxip0 ? spi1ip2 spi1ip1 spi1ip0 ? spf1ip2 spf1ip1 spf1ip0 ?t3ip2t3ip1t3ip0 4444 ipc3 00aa ? nvmip2 nvmip1 nvmip0 ? ? ? ? ? ad1ip2 ad1ip1 ad1ip0 ? u1txip2 u1txip1 u1txip0 4044 ipc4 00ac ? cnip2 cnip1 cnip0 ? cmip2 cmip1 cmip0 ? mi2c1p2 mi2c1p1 mi2c1p0 ? si2c1p2 si2c1p1 si2c1p0 4444 ipc5 00ae ? ? ? ? ? ? ? ? ? ? ? ? ? int1ip2 int1ip1 int1ip0 0004 ipc7 00b2 ? ? ? ? ? ? ? ? ? int2ip2 int2ip1 int2ip0 ? ? ? ? 4440 ipc16 00c4 ? ? ? ? ? ? ? ? ? u1erip2 u1erip1 u1erip0 ? ? ? ? 4440 ipc18 00c8 ? ? ? ? ? ? ? ? ? ? ? ? ? hlvdip2 hlvdip1 hlvdip0 0004 ipc19 00ca ? ? ? ? ? ? ? ? ? ctmuip2 ctmuip1 ctmuip0 ? ? ? ? 0040 inttreg 00e0 cpuirq ?vhold ? ilr3 ilr2 ilr1 ilr0 ? vecnum6 vecnum5 vecnum4 vecnum3 vecnum2 vecnum1 vecnum0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
? 2009 microchip technology inc. preliminary ds39937b-page 31 pic24f04ka201 family table 4-6: timer register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets tmr1 0100 timer1 register 0000 pr1 0102 timer1 period register ffff t1con 0104 ton ?tsidl ? ? ? ? ? ? tgate tckps1 tckps0 ? tsync tcs ? 0000 tmr2 0106 timer2 register 0000 tmr3hld 0108 timer3 holding register (for 32-bit timer operations only) 0000 tmr3 010a timer3 register 0000 pr2 010c timer2 period register ffff pr3 010e timer3 period register ffff t2con 0110 ton ?tsidl ? ? ? ? ? ? tgate tckps1 tckps0 t32 ?tcs ? 0000 t3con 0112 ton ?tsidl ? ? ? ? ? ? tgate tckps1 tckps0 ? ?tcs ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-7: input capture register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets ic1buf 0140 input capture 1 register ffff ic1con 0142 ? ?icsidl ? ? ? ? ? ictmr ici1 ici0 icov icbne icm2 icm1 icm0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-8: output compare register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets oc1rs 0180 output compare 1 secondary register ffff oc1r 0182 output compare 1 register ffff oc1con 0184 ? ?ocsidl ? ? ? ? ? ? ? ? ocflt octsel ocm2 ocm1 ocm0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
pic24f04ka201 family ds39937b-page 32 preliminary ? 2009 microchip technology inc. table 4-9: i 2 c? register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets i2c1rcv 0200 ? ? ? ? ? ? ? ? i2c1 receive register 0000 i2c1trn 0202 ? ? ? ? ? ? ? ? i2c1 transmit register 00ff i2c1brg 0204 ? ? ? ? ? ? ? i2c1 baud rate generator register 0000 i2c1con 0206 i2cen ? i2csidl sclrel ipmien a10m disslw smen gcen stren ackdt acken rcen pen rsen sen 1000 i2c1stat 0208 ackstat trstat ? ? ? bcl gcstat add10 iwcol i2cov d/a psr/w rbf tbf 0000 i2c1add 020a ? ? ? ? ? ? i2c1 address register 0000 i2c1msk 020c ? ? ? ? ? ? amsk9 amsk8 amsk7 amsk6 amsk5 amsk4 amsk3 amsk2 amsk1 amsk0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-10: uart register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets u1mode 0220 uarten ? usidl iren rtsmd ? uen1 uen0 wake lpback abaud rxinv brgh pdsel1 pdsel0 stsel 0000 u1sta 0222 utxisel1 utxinv utxisel0 ? utxbrk utxen utxbf trmt urxisel1 urxisel0 adden ridle perr ferr oerr urxda 0110 u1txreg 0224 ? ? ? ? ? ? ? uart1 transmit register 0000 u1rxreg 0226 ? ? ? ? ? ? ? uart1 receive register 0000 u1brg 0228 baud rate generator prescaler register 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-11: spi register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets spi1stat 0240 spien ? spisidl ? ? spibec2 spibec1 spibec0 srmpt spirov srxmpt sisel2 sisel1 sisel0 spitbf spirbf 0000 spi1con1 0242 ? ? ? dissck dissdo mode16 smp cke ssen ckp msten spre2 spre1 spre0 ppre1 ppre0 0000 spi1con2 0244 frmen spifsd spifpol ? ? ? ? ? ? ? ? ? ? ? spife spiben 0000 spi1buf 0248 spi1 transmit/receive buffer 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
? 2009 microchip technology inc. preliminary ds39937b-page 33 pic24f04ka201 family table 4-12: porta register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 (1) bit 4 bit 3 bit 2 bit 1 bit 0 all resets trisa 02c0 ? ? ? ? ? ? ? ? ? trisa6 ? trisa4 trisa3 (2,3) trisa2 (2) trisa1 trisa0 00df porta 02c2 ? ? ? ? ? ? ? ? ? ra6 ra5 ra4 ra3 (2,3) ra2 (2) ra1 ra0 xxxx lata 02c4 ? ? ? ? ? ? ? ? ? lata6 ?lata4lata3 (2,3) lata2 (2) lata1 lata0 xxxx odca 02c6 ? ? ? ? ? ? ? ? ? oda6 ? oda4 oda3 (2,3) oda2 (2) oda1 oda0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: bit available only when mclre = 0 . 2: bits are available only when the primary oscillator is disabled (poscmd1:poscmd0 = 00 ); otherwise read as ? 0 ?. 3: bits are available only when the primary oscillator is disabled or ec mode is selected (poscmd1:poscmd0 = 00 or 11 ) and clko is disabled (osciofnc = 0 ); otherwise read as ? 0 ?. table 4-13: portb register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets trisb 02c8 trisb15 trisb14 trisb13 (1) trisb12 (1) ? ? trisb9 trisb8 trisb7 ? ?trisb4 ? trisb2 (1) trisb1 (1) trisb0 (1) ffff portb 02ca rb15 rb14 rb13 (1) rb12 (1) ? ?rb9rb8rb7 ? ?rb4 ?rb2 (1) rb1 (1) rb0 (1) xxxx latb 02cc latb15 latb14 latb13 (1) latb12 (1) ? ? latb9 latb8 latb7 ? ?latb4 ?latb2 (1) latb1 (1) latb0 (1) xxxx odcb 02ce odb15 odb14 odb13 (1) odb12 (1) ? ? odb9 odb8 odb7 ? ?odb4 ?odb2 (1) odb1 (1) odb (1) 0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits are not implemented on 14-pin devices. table 4-14: pad config uration register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets padcfg1 02fc ? ? ? ? ? ? ? ? ? ? ? smbusdel oc1tris ? ? ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
pic24f04ka201 family ds39937b-page 34 preliminary ? 2009 microchip technology inc. table 4-15: adc register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets adc1buf0 0300 adc data buffer 0 xxxx adc1buf1 0302 adc data buffer 1 xxxx adc1buf2 0304 adc data buffer 2 xxxx adc1buf3 0306 adc data buffer 3 xxxx adc1buf4 0308 adc data buffer 4 xxxx adc1buf5 030a adc data buffer 5 xxxx adc1buf6 030c adc data buffer 6 xxxx adc1buf7 030e adc data buffer 7 xxxx adc1buf8 0310 adc data buffer 8 xxxx adc1buf9 0312 adc data buffer 9 xxxx adc1bufa 0314 adc data buffer 10 xxxx adc1bufb 0316 adc data buffer 11 xxxx adc1bufc 0318 adc data buffer 12 xxxx adc1bufd 031a adc data buffer 13 xxxx adc1bufe 031c adc data buffer 14 xxxx adc1buff 031e adc data buffer 15 xxxx ad1con1 0320 adon ?adsidl ? ? ? form1 form0 ssrc2 ssrc1 ssrc0 ? ? asam samp done 0000 ad1con2 0322 vcfg2 vcfg1 vcfg0 offcal ? cscna ? ?bufs ? smpi3 smpi2 smpi1 smpi0 bufm alts 0000 ad1con3 0324 adrc ? ? samc4 samc3 samc2 samc1 samc0 ? ? adcs5 adcs4 adcs3 adcs2 adcs1 adcs0 0000 ad1chs 0328 ch0nb ? ? ? ch0sb3 ch0sb2 ch0sb1 ch0sb0 ch0na ? ? ch0sa4 ch0sa3 ch0sa2 ch0sa1 ch0sa0 0000 ad1pcfg 032c ? ? ?pcfg12 (1) pcfg11 (1) pcfg10 ? ? ? ? pcfg5 pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 0000 ad1cssl 0330 ? ? ? cssl12 (1) cssl11 (1) cssl10 ? ? ? ? cssl5 cssl4 cssl3 cssl2 cssl1 cssl0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: these bits are not implemented on 14-pin devices. table 4-16: ctmu register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets ctmucon 033c ctmuen ? ctmusidl tgen edgen edgseqen idissen cttrig edg2pol edg2sel1 edg2sel0 edg1pol edg1sel1 edg1sel0 edg2stat edg1stat 0000 ctmuicon 033e itrim5 itrim4 itrim3 itrim2 itrim1 itrim0 irng1 irng0 ? ? ? ? ? ? ? ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
? 2009 microchip technology inc. preliminary ds39937b-page 35 pic24f04ka201 family table 4-17: dual comparator register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets cmstat 0630 cmsidl ? ? ? ? ? c2evt c1evt ? ? ? ? ? ? c2out c1out 0000 cvrcon 0632 ? ? ? ? ? ? ? ? cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 0000 cm1con 0634 con coe cpol clpwr ? ? cevt cout evpol1 evpol0 ?cref ? ? cch1 cch0 0000 cm2con 0636 con coe cpol clpwr ? ? cevt cout evpol1 evpol0 ?cref ? ? cch1 cch0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. table 4-18: clock control register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets rcon 0740 trapr iopuwr sboren ? ? dpslp ? pmslp extr swr swdten wdto sleep idle bor por (note 1) osccon 0742 ? cosc2 cosc1 cosc0 ? nosc2 nosc1 nosc0 clklock ? lock ?cf ? soscen oswen (note 2) clkdiv 0744 roi doze2 doze1 doze0 dozen rcdiv2 rcdiv1 rcdiv0 ? ? ? ? ? ? ? ? 3140 osctun 0748 ? ? ? ? ? ? ? ? ? ? tun5 tun4 tun3 tun2 tun1 tun0 0000 refocon 074e roen ? rosslp rosel rodiv3 rodiv2 rodiv1 rodiv0 ? ? ? ? ? ? ? ? 0000 hlvdcon 0756 hlvden ?hlsidl ? ? ? ? ? vdir bgvst irvst ? hlvdl3 hlvdl2 hlvdl1 hlvdl0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: rcon register reset values are dependent on type of reset. 2: osccon register reset values are dependent on configuration fuses and by type of reset. table 4-19: deep sleep register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets (1) dscon 0758 dsen ? ? ? ? ? ? ? ? ? ? ? ? ? dsbor release 0000 dswsrc 075a ? ? ? ? ? ? ?dsint0dsflt ? ?dswdt ?dsmclr ? dspor 0000 dsgpr0 075c deep sleep general purpose register 0 0000 dsgpr1 075e deep sleep general purpose register 1 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: the deep sleep registers are only reset on a v dd por event.
pic24f04ka201 family ds39937b-page 36 preliminary ? 2009 microchip technology inc. table 4-20: nvm register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets nvmcon 0760 wr wren wrerr pgmonly ? ? ? ? ? erase nvmop5 nvmop4 nvmop3 nvmop2 nvmop1 nvmop0 0000 (1) nvmkey 0766 ? ? ? ? ? ? ? ? nvmkey7 nvmkey6 nvmkey5 nvmkey4 nvmkey3 nvmkey2 nvmkey1 nvmkey0 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal. note 1: reset value shown is for por only. value on other reset states is dependent on the state of memory write or erase operations at the time of reset. table 4-21: pmd register map file name addr bit 15 bit 14 bit 13 bit 12 bit 11 bit 10 bit 9 bit 8 bit 7 bit 6 bit 5 bit 4 bit 3 bit 2 bit 1 bit 0 all resets pmd1 0770 ? ? t3md t2md t1md ? ? ? i2c1md ?u1md ? spi1md ? ?adc1md 0000 pmd2 0772 ? ? ? ? ? ? ?ic1md ? ? ? ? ? ? ?oc1md 0000 pmd3 0774 ? ? ? ? ? cmpmd ? ? ? ? ? ? ? ? ? ? 0000 pmd4 0776 ? ? ? ? ? ? ? ? ? ? ? ? refomd ctmumd hlvdmd ? 0000 legend: ? = unimplemented, read as ? 0 ?. reset values are shown in hexadecimal.
? 2009 microchip technology inc. preliminary ds39937b-page 37 pic24f04ka201 family 4.2.5 software stack in addition to its use as a working register, the w15 register in pic24f devices is also used as a software stack pointer. the pointer always points to the first available free word and grows from lower to higher addresses. it pre-decrements for stack pops and post-increments for stack pushes, as depicted in figure 4-4. for a pc push during any call instruction, the msb of the pc is zero-extended before the push, ensuring that the msb is always clear. the stack pointer limit value (splim) register, associated with the stack pointer, sets an upper address boundary for the stack. splim is uninitialized at reset. as is the case for the stack pointer, splim<0> is forced to ? 0 ? as all stack operations must be word-aligned. whenever an ea is generated using w15 as a source or destination pointer, the resulting address is compared with the value in splim. if the contents of the stack pointer (w15) and the splim register are equal, and a push operation is performed, a stack error trap will not occur. the stack error trap will occur on a subsequent push operation. thus, for example, if it is desirable to cause a stack error trap when the stack grows beyond address 09ff in ram, initialize the splim with the value, 09fd. similarly, a stack pointer underflow (stack error) trap is generated when the stack pointer address is found to be less than 0800h. this prevents the stack from interfering with the special function register (sfr) space. figure 4-4: call stack frame 4.3 interfacing program and data memory spaces the pic24f architecture uses a 24-bit wide program space and 16-bit wide data space. the architecture is also a modified harvard scheme, meaning that data can also be present in the program space. to use this data successfully, it must be accessed in a way that preserves the alignment of information in both spaces. apart from the normal execution, the pic24f architecture provides two methods by which the program space can be accessed during operation: ? using table instructions to access individual bytes or words anywhere in the program space ? remapping a portion of the program space into the data space, psv table instructions allow an application to read or write small areas of the program memory. this makes the method ideal for accessing data tables that need to be updated from time to time. it also allows access to all bytes of the program word. the remapping method allows an application to access a large block of data on a read-only basis, which is ideal for look ups from a large table of static data. it can only access the least significant word (lsw) of the program word. 4.3.1 addressing program space since the address ranges for the data and program spaces are 16 and 24 bits, respectively, a method is needed to create a 23-bit or 24-bit program address from 16-bit data registers. the solution depends on the interface method to be used. for table operations, the 8-bit table memory page address register (tblpag) is used to define a 32k word region within the program space. this is concatenated with a 16-bit ea to arrive at a full 24-bit program space address. in this format, the most significant bit (msb) of tblpag is used to determine if the operation occurs in the user memory (tblpag<7> = 0 ) or the configuration memory (tblpag<7> = 1 ). for remapping operations, the 8-bit program space visibility page address register (psvpag) is used to define a 16k word page in the program space. when the msb of the ea is ? 1 ?, psvpag is concatenated with the lower 15 bits of the ea to form a 23-bit program space address. unlike the table operations, this limits remapping operations strictly to the user memory area. see table 4-22 and figure 4-5 to know how the program ea is created for table operations and remapping accesses from the data ea. here, p<23:0> refers to a program space word, whereas d<15:0> refers to a data space word. note: a pc push during exception processing will concatenate the srl register to the msb of the pc prior to the push. note: a write to the splim register should not be immediately followed by an indirect read operation using w15. pc<15:0> 000000000 0 15 w15 (before call) w15 (after call) stack grows towards higher address 0000h pc<22:16> pop : [--w15] push : [w15++]
pic24f04ka201 family ds39937b-page 38 preliminary ? 2009 microchip technology inc. table 4-22: program space address construction figure 4-5: data access from program space address generation access type access space program space address <23> <22:16> <15> <14:1> <0> instruction access (code execution) user 0 pc<22:1> 0 0xx xxxx xxxx xxxx xxxx xxx0 tblrd/tblwt (byte/word read/write) user tblpag<7:0> data ea<15:0> 0xxx xxxx xxxx xxxx xxxx xxxx configuration tblpag<7:0> data ea<15:0> 1xxx xxxx xxxx xxxx xxxx xxxx program space visibility (block remap/read) user 0 psvpag<7:0> (2) data ea<14:0> (1) 0 xxxx xxxx xxx xxxx xxxx xxxx note 1: data ea<15> is always ? 1 ? in this case, but is not used in calculating the program space address. bit 15 of the address is psvpag<0>. 2: psvpag can have only one value (? 00 ? to access program memory) on the pic24f04ka201 family. 0 program counter 23 bits 1 psvpag 8 bits ea 15 bits program counter (1) select tblpag 8 bits ea 16 bits byte select 0 0 1/0 user/configuration table operations (2) program space visibility (1) space select 24 bits 23 bits (remapping) 1/0 0 note 1: the lsb of program space addres ses is always fixed as ? 0 ? in order to maintain word alignment of data in the program and data spaces. 2: table operations are not required to be word-aligned. t able read operations are permi tted in the configuration memory space.
? 2009 microchip technology inc. preliminary ds39937b-page 39 pic24f04ka201 family 4.3.2 data access from program memory using table instructions the tblrdl and tblwtl instructions offer a direct method of reading or writing the lower word of any address within the program memory without going through data space. the tblrdh and tblwth instruc- tions are the only method to read or write the upper 8 bits of a program space word as data. the pc is incremented by 2 for each successive 24-bit program word. this allows program memory addresses to directly map to data space addresses. program memory can thus be regarded as two 16-bit word-wide address spaces, residing side by side, each with the same address range. tblrdl and tblwtl access the space which contains the least significant data word, and tblrdh and tblwth access the space which contains the upper data byte. two table instructions are provided to move byte or word-sized (16-bit) data to and from program space. both function as either byte or word operations. 1. tblrdl (table read low): in word mode, it maps the lower word of the program space location (p<15:0>) to a data address (d<15:0>). in byte mode, either the upper or lower byte of the lower program word is mapped to the lower byte of a data address. the upper byte is selected when byte select is ? 1 ?; the lower byte is selected when it is ? 0 ?. 2. tblrdh (table read high): in word mode, it maps the entire upper word of a program address (p<23:16>) to a data address. note that d<15:8>, the ?phantom? byte, will always be ? 0 ?. in byte mode, it maps the upper or lower byte of the program word to d<7:0> of the data address, as above. note that the data will always be ? 0 ? when the upper ?phantom? byte is selected (byte select = 1 ). in a similar fashion, two table instructions, tblwth and tblwtl , are used to write individual bytes or words to a program space address. the details of their operation are explained in section 5.0 ?flash program memory? . for all table operations, the area of program memory space to be accessed is determined by the table memory page address register (tblpag). tblpag covers the entire program memory space of the device, including user and configuration spaces. when tblpag<7> = 0 , the table page is located in the user memory space. when tblpag<7> = 1 , the page is located in configuration space. note: only table read operations will execute in the configuration memory space, and only then, in implemented areas such as the device id. table write operations are not allowed.
pic24f04ka201 family ds39937b-page 40 preliminary ? 2009 microchip technology inc. figure 4-6: accessing program memory with table instructions 4.3.3 reading data from program memory using program space visibility the upper 32 kbytes of data space may optionally be mapped into an 8k word page (in pic24f08ka1xx devices) and a 16k word page (in pic24f16ka1xx devices) of the program space. this provides transparent access of stored constant data from the data space without the need to use special instructions (i.e., tblrdl/h ). program space access through the data space occurs if the msb of the data space ea is ? 1 ?, and psv is enabled by setting the psv bit in the cpu control (corcon<2>) register. the location of the program memory space to be mapped into the data space is determined by the program space visibility page address register (psvpag). this 8-bit register defines any one of 256 possible pages of 16k words in pro- gram space. in effect, psvpag functions as the upper 8 bits of the program memory address, with the 15 bits of the ea functioning as the lower bits. by incrementing the pc by 2 for each program memory word, the lower 15 bits of data space addresses directly map to the lower 15 bits in the corresponding program space addresses. data reads from this area add an additional cycle to the instruction being executed, since two program memory fetches are required. although each data space address, 8000h and higher, maps directly into a corresponding program memory address (see figure 4-7), only the lower 16 bits of the 24-bit program word are used to contain the data. the upper 8 bits of any program space locations used as data should be programmed with ? 1111 1111 ? or ? 0000 0000 ? to force a nop . this prevents possible issues should the area of code ever be accidentally executed. for operations that use psv and are executed outside a repeat loop, the mov and mov.d instructions will require one instruction cycle in addition to the specified execution time. all other instructions will require two instruction cycles in addition to the specified execution time. for operations that use psv, which are executed inside a repeat loop, there will be some instances that require two instruction cycles in addition to the specified execution time of the instruction: ? execution in the first iteration ? execution in the last iteration ? execution prior to exiting the loop due to an interrupt ? execution upon re-entering the loop after an interrupt is serviced 0 8 16 23 00000000 00000000 00000000 00000000 ?phantom? byte tblrdh.b (wn<0> = 0 ) tblrdl.w tblrdl.b (wn<0> = 1 ) tblrdl.b (wn<0> = 0 ) 23 15 0 tblpag 00 000000h 800000h 002bfeh program space data ea<15:0> the address for the table operation is determined by the data ea within the page defined by the tblpag register. only read operations are provided; write op erations are also valid in the user memory area. note: psv access is temporarily disabled during table reads/writes.
? 2009 microchip technology inc. preliminary ds39937b-page 41 pic24f04ka201 family any other iteration of the repeat loop will allow the instruction accessing data, using psv, to execute in a single cycle. figure 4-7: program spac e visibility operation 23 15 0 psvpag data space program space 0000h 8000h ffffh 00 000000h 800000h 002bfeh when corcon<2> = 1 and ea<15> = 1 : psv area the data in the page designated by psvpag is mapped into the upper half of the data memory space.... data ea<14:0> ...while the lower 15 bits of the ea specify an exact address within the psv area. this corresponds exactly to the same lower 15 bits of the actual program space address.
pic24f04ka201 family ds39937b-page 42 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 43 pic24f04ka201 family 5.0 flash program memory the pic24f04ka201 family of devices contains internal flash program memory for storing and executing application code. the memory is readable, writable and erasable when operating with v dd over 1.8v. flash memory can be programmed in three ways: ? in-circuit serial programming? (icsp?) ? run-time self programming (rtsp) ? enhanced in-circuit serial programming (enhanced icsp) icsp allows a pic24fxxxx device to be serially pro- grammed while in the end application circuit. this is simply done with two lines for the programming clock and programming data (which are named pgcx and pgdx, respectively), and three other lines for power (v dd ), ground (v ss ) and master clear/program mode entry voltage (mclr /v pp ). this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or custom firmware to be programmed. real-time streaming protocol (rtsp) is accomplished using tblrd (table read) and tblwt (table write) instructions. with rtsp, the user may write program memory data in blocks of 32 instructions (96 bytes) at a time, and erase program memory in blocks of 32, 64 and 128 instructions (96,192 and 384 bytes) at a time. the nvmop<1:0> (nvmcon<1:0>) bits decide the erase block size. 5.1 table instructions and flash programming regardless of the method used, flash memory programming is done with the table read and write instructions. these allow direct read and write access to the program memory space from the data memory while the device is in normal operating mode. the 24-bit target address in the program memory is formed using the tblpag<7:0> bits and the effective address (ea) from a w register, specified in the table instruction, as depicted in figure 5-1. the tblrdl and the tblwtl instructions are used to read or write to bits<15:0> of program memory. tblrdl and tblwtl can access program memory in both word and byte modes. the tblrdh and tblwth instructions are used to read or write to bits<23:16> of program memory. tblrdh and tblwth can also access program memory in word or byte mode. figure 5-1: addressing for table registers note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on flash programming, refer to the ?pic24f family reference manual? , section 4. ?program memory? (ds39715). 0 program counter 24 bits program tblpag reg 8 bits working reg ea 16 bits using byte 24-bit ea 0 1/0 select table instruction counter using user/configuration space select
pic24f04ka201 family ds39937b-page 44 preliminary ? 2009 microchip technology inc. 5.2 rtsp operation the pic24f flash program memory array is organized into rows of 32 instructions or 96 bytes. rtsp allows the user to erase blocks of 1 row, 2 rows and 4 rows (32, 64 and 128 instructions) at a time and to program one row at a time. it is also possible to program single words. the 1-row (96 bytes), 2-row (192 bytes) and 4-row (384 bytes) erase blocks and single row write block (96 bytes) are edge-aligned, from the beginning of program memory. when data is written to program memory using tblwt instructions, the data is not written directly to memory. instead, data written using table writes is stored in holding latches until the programming sequence is executed. any number of tblwt instructions can be executed and a write will be successfully performed. however, 32 tblwt instructions are required to write the full row of memory. the basic sequence for rtsp programming is to set up a table pointer, then do a series of tblwt instructions to load the buffers. programming is performed by setting the control bits in the nvmcon register. data can be loaded in any order and the holding registers can be written to multiple times before performing a write operation. subsequent writes, however, will wipe out any previous writes. all of the table write operations are single-word writes (two instruction cycles), because only the buffers are written. a programming cycle is required for programming each row. 5.3 enhanced in-circuit serial programming enhanced icsp uses an on-board bootloader, known as the program executive, to manage the programming process. using an spi data frame format, the program executive can erase, program and verify program memory. for more information on enhanced icsp, see the device programming specification. 5.4 control registers there are two sfrs used to read and write the program flash memory: nvmcon and nvmkey. the nvmcon register (register 5-1) controls the blocks that need to be erased, which memory type is to be programmed and when the programming cycle starts. nvmkey is a write-only register that is used for write protection. to start a pr ogramming or erase sequence, the user must consecutively write 55h and aah to the nvmkey register. refer to section 5.5 ?programming operations? for further details. 5.5 programming operations a complete programming sequence is necessary for programming or erasing the internal flash in rtsp mode. during a programming or erase operation, the processor stalls (waits) until the operation is finished. setting the wr bit (nvmcon<15>) starts the operation and the wr bit is automatically cleared when the operation is finished. note: writing to a location multiple times without erasing it is not recommended.
? 2009 microchip technology inc. preliminary ds39937b-page 45 pic24f04ka201 family register 5-1: nvmcon: flash memory control register r/so-0, hc r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 wr wren wrerr pgmonly ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? erase nvmop5 (1) nvmop4 (1) nvmop3 (1) nvmop2 (1) nvmop1 (1) nvmop0 (1) bit 7 bit 0 legend: so = settable only bit hc = hardware clearable bit -n = value at por ?1? = bit is set r = readable bit w = writable bit ?0? = bit is cleared x = bit is unknown u = unimplemented bit, read as ?0? bit 15 wr: write control bit 1 = initiates a flash memory program or erase operation. the operation is self-timed and the bit is cleared by hardware once the operation is complete 0 = program or erase operation is complete and inactive bit 14 wren: write enable bit 1 = enable flash program/erase operations 0 = inhibit flash program/erase operations bit 13 wrerr: write sequence error flag bit 1 = an improper program or erase sequence attempt or termination has occurred (bit is set automatically on any set attempt of the wr bit) 0 = the program or erase operation completed normally bit 12 pgmonly: program only enable bit bit 11-7 unimplemented: read as ? 0 ? bit 6 erase: erase/program enable bit 1 = perform the erase operation specified by nvmop<5:0> on the next wr command 0 = perform the program operation specified by nvmop<5:0> on the next wr command bit 5-0 nvmop<5:0>: programming operation command byte bits (1) erase operations (when erase bit is ? 1 ?): 1010xx = erase entire boot block (including code-protected boot block) (2) 1001xx = erase entire memory (including boot block, configuration block, general block) (2) 011010 = program/erase 4 rows of flash memory (3) 011001 = program/erase 2 rows of flash memory (3) 011000 = program/erase 1 row of flash memory (3) 0101xx = erase entire configuration block (except code protection bits) 0011xx = erase entire general memory block programming operations note 1: all other combinations of nvmop<5:0> are no operation. 2: available in icsp? mode only. refer to device programming specification. 3: the address in the table pointer decides which rows will be erased.
pic24f04ka201 family ds39937b-page 46 preliminary ? 2009 microchip technology inc. 5.5.1 programming algorithm for flash program memory the user can program one row of flash program memory at a time by erasing the programmable row. the general process is: 1. read a row of program memory (32 instructions) and store in data ram. 2. update the program data in ram with the desired new data. 3. erase a row (see example 5-1): a) set the nvmop bits (nvmcon<5:0>) to ? 011000 ? to configure for row erase. set the erase (nvmcon<6>) and wren (nvmcon<14>) bits. b) write the starting address of the block to be erased into the tblpag and w registers. c) write 55h to nvmkey. d) write aah to nvmkey. e) set the wr bit (nvmcon<15>). the erase cycle begins and the cpu stalls for the duration of the erase cycle. when the erase is done, the wr bit is cleared automatically. 4. write the first 32 instructions from data ram into the program memory buffers (see example 5-1). 5. write the program block to flash memory: a) set the nvmop bits to ? 011000 ? to configure for row programming. clear the erase bit and set the wren bit. b) write 55h to nvmkey. c) write aah to nvmkey. d) set the wr bit. the programming cycle begins and the cpu stalls for the duration of the write cycle. when the write to flash memory is done, the wr bit is cleared automatically. for protection against accidental operations, the write initiate sequence for nvmkey must be used to allow any erase or program operation to proceed. after the programming command has been executed, the user must wait for the programming time until programming is complete. the two instructions following the start of the programming sequence should be nop s, as displayed in example 5-5. example 5-1: erasing a program memo ry row ? assembly language code ; set up nvmcon for row erase operation mov #0x4058, w0 ; mov w0, nvmcon ; initialize nvmcon ; init pointer to row to be erased mov #tblpage(prog_addr), w0 ; mov w0, tblpag ; initialize pm page boundary sfr mov #tbloffset(prog_addr), w0 ; initialize in-page ea[15:0] pointer tblwtl w0, [w0] ; set base address of erase block disi #5 ; block all interrupts for next 5 instructions mov #0x55, w0 mov w0, nvmkey ; write the 55 key mov #0xaa, w1 ; mov w1, nvmkey ; write the aa key bset nvmcon, #wr ; start the erase sequence nop ; insert two nops after the erase nop ; command is asserted
? 2009 microchip technology inc. preliminary ds39937b-page 47 pic24f04ka201 family example 5-2: erasing a program me mory row ? ?c? language code // c example using mplab c30 int __attribute__ ((space(auto_psv))) progaddr = &progaddr; // variable located in pgm memory unsigned int offset; //set up pointer to the first memory location to be written tblpag = __builtin_tblpage(&progaddr); // initialize pm page boundary sfr offset = &progaddr & 0xffff; // initialize lower word of address __builtin_tblwtl(offset, 0x0000); // set base address of erase block // with dummy latch write nvmcon = 0x4058; // initialize nvmcon asm("disi #5"); // block all interrupts for next 5 instructions __builtin_write_nvm(); // c30 function to perform unlock // sequence and set wr
pic24f04ka201 family ds39937b-page 48 preliminary ? 2009 microchip technology inc. example 5-3: loading the write bu ffers ? assembly language code example 5-4: loading the write buffers ? ?c? language code ; set up nvmcon for row programming operations mov #0x4004, w0 ; mov w0, nvmcon ; initialize nvmcon ; set up a pointer to the first program memory location to be written ; program memory selected, and writes enabled mov #0x0000, w0 ; mov w0, tblpag ; initialize pm page boundary sfr mov #0x6000, w0 ; an example program memory address ; perform the tblwt instructions to write the latches ; 0th_program_word mov #low_word_0, w2 ; mov #high_byte_0, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0++] ; write pm high byte into program latch ; 1st_program_word mov #low_word_1, w2 ; mov #high_byte_1, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0++] ; write pm high byte into program latch ; 2nd_program_word mov #low_word_2, w2 ; mov #high_byte_2, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0++] ; write pm high byte into program latch ? ? ? ; 32nd_program_word mov #low_word_31, w2 ; mov #high_byte_31, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0] ; write pm high byte into program latch // c example using mplab c30 #define num_instruction_per_row 64 int __attribute__ ((space(auto_psv))) progaddr = &progaddr; // variable located in pgm memory unsigned int offset; unsigned int i; unsigned int progdata[2*num_instruction_per_row]; // buffer of data to write //set up nvmcon for row programming nvmcon = 0x4001; // initialize nvmcon //set up pointer to the first memory location to be written tblpag = __builtin_tblpage(&progaddr); // initialize pm page boundary sfr offset = &progaddr & 0xffff; // initialize lower word of address //perform tblwt instructions to write necessary number of latches for(i=0; i < 2*num_instruction_per_row; i++) { __builtin_tblwtl(offset, progdata[i++]); // write to address low word __builtin_tblwth(offset, progdata[i]); // write to upper byte offset = offset + 2; // increment address }
? 2009 microchip technology inc. preliminary ds39937b-page 49 pic24f04ka201 family example 5-5: initiating a programming sequence ? assembly language code example 5-6: initiating a programmi ng sequence ? ?c ? language code example 5-7: programming a single word of flash program memory disi #5 ; block all interrupts for next 5 instructions mov #0x55, w0 mov w0, nvmkey ; write the 55 key mov #0xaa, w1 ; mov w1, nvmkey ; write the aa key bset nvmcon, #wr ; start the erase sequence nop ; 2 nops required after setting wr nop ; btsc nvmcon, #15 ; wait for the sequence to be completed bra $-2 ; // c example using mplab c30 asm("disi #5"); // block all interrupts for next 5 instructions __builtin_write_nvm(); // perform unlock sequence and set wr ; setup a pointer to data program memory mov #tblpage(prog_addr), w0 ; mov w0, tblpag ;initialize pm page boundary sfr mov #tbloffset(prog_addr), w0 ;initialize a register with program memory address mov #low_word_n, w2 ; mov #high_byte_n, w3 ; tblwtl w2, [w0] ; write pm low word into program latch tblwth w3, [w0++] ; write pm high byte into program latch ; setup nvmcon for programming one word to data program memory mov #0x4003, w0 ; mov w0, nvmcon ; set nvmop bits to 0011 disi #5 ; disable interrupts while the key sequence is written mov #0x55, w0 ; write the key sequence mov w0, nvmkey mov #0xaa, w0 mov w0, nvmkey bset nvmcon, #wr ; start the write cycle
pic24f04ka201 family ds39937b-page 50 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 51 pic24f04ka201 family 6.0 resets the reset module combines all reset sources and controls the device master reset signal, sysrst . the following is a list of device reset sources: ? por: power-on reset ?mclr : pin reset ?swr: reset instruction ? wdtr: watchdog timer reset ? bor: brown-out reset ? low-power bor/deep sleep bor ? trapr: trap conflict reset ? iopuwr: illegal opcode reset ? uwr: uninitialized w register reset figure 6-1 displays a simplified block diagram of the reset module. any active source of reset will make the sysrst signal active. many registers associated with the cpu and peripherals are forced to a known reset state. most registers are unaffected by a reset; their status is unknown on power-on reset (por) and unchanged by all other resets. all types of device reset will set a corresponding status bit in the rcon register to indicate the type of reset (see register 6-1). a por will clear all bits except for the bor and por bits (rcon<1:0>) which are set. the user may set or clear any bit at any time during code execution. the rcon bits only serve as status bits. setting a particular reset status bit in software will not cause a device reset to occur. the rcon register also has other bits associated with the watchdog timer (wdt) and device power-saving states. the function of these bits is discussed in other sections of this manual. figure 6-1: reset sy stem block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on resets, refer to the ?pic24f family reference manual? , section 40. ?reset with programmable brown-out reset? (ds39728). note: refer to the specific peripheral or cpu section of this manual for register reset states. note: the status bits in the rcon register should be cleared after they are read so that the next rcon register value after a device reset will be meaningful. mclr v dd v dd rise detect por sleep or idle brown-out reset reset instruction wdt module glitch filter bor trap conflict illegal opcode uninitialized w register sysrst boren<1:0> 00 01 10 11 0 rcon sleep 1
pic24f04ka201 family ds39937b-page 52 preliminary ? 2009 microchip technology inc. register 6-1: rcon: re set control register (1) r/w-0, hs r/w-0, hs r/w-0 u-0 u-0 r/c-0, hs u-0 r/w-0 trapr iopuwr sboren ? ? dpslp ?pmslp bit 15 bit 8 r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs r/w-1, hs r/w-1, hs extr swr swdten (2) wdto sleep idle bor por bit 7 bit 0 legend: c = clearable bit hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 trapr: trap reset flag bit 1 = a trap conflict reset has occurred 0 = a trap conflict reset has not occurred bit 14 iopuwr: illegal opcode or uninitialized w access reset flag bit 1 = an illegal opcode detection, an illegal address mode or uninitialized w register used as an address pointer caused a reset 0 = an illegal opcode or uninitialized w reset has not occurred bit 13 sboren: software enable/disable of bor bit 1 = bor is turned on in software 0 = bor is turned off in software bit 12-11 unimplemented: read as ? 0 ? bit 10 dpslp: deep sleep mode flag bit 1 = deep sleep has occurred 0 = deep sleep has not occurred bit 9 unimplemented: read as ? 0 ? bit 8 pmslp: program memory power during sleep/idle bit 1 = program memory bias voltage remains powered during sleep/idle 0 = program memory bias voltage is powered down during sleep/idle bit 7 extr: external reset (mclr ) pin bit 1 = a master clear (pin) reset has occurred 0 = a master clear (pin) reset has not occurred bit 6 swr: software reset (instruction) flag bit 1 = a reset instruction has been executed 0 = a reset instruction has not been executed bit 5 swdten: software enable/disable of wdt bit (2) 1 = wdt is enabled 0 = wdt is disabled bit 4 wdto: watchdog timer time-out flag bit 1 = wdt time-out has occurred 0 = wdt time-out has not occurred bit 3 sleep: wake-up from sleep flag bit 1 = device has been in sleep mode 0 = device has not been in sleep mode bit 2 idle: wake-up from idle flag bit 1 = device has been in idle mode 0 = device has not been in idle mode bit 1 bor: brown-out reset flag bit 1 = a brown-out reset has occurred (the bor is also set after a por) 0 = a brown-out reset has not occurred
? 2009 microchip technology inc. preliminary ds39937b-page 53 pic24f04ka201 family table 6-1: reset flag bit operation 6.1 clock source selection at reset if clock switching is enabled, the system clock source at device reset is chosen as shown in table 6-2. if clock switching is disabled, the system clock source is always selected according to the oscillator configuration bits. refer to section 8.0 ?oscillator configuration? for further details. table 6-2: oscillator selection vs. type of reset (clock switching enabled) bit 0 por: power-on reset flag bit 1 = a power-up reset has occurred 0 = a power-up reset has not occurred note 1: all of the reset status bits may be set or cleared in software. setting one of these bits in software does not cause a device reset. 2: if the fwdten configuration bit is ? 1 ? (unprogrammed), the wdt is always enabled, regardless of the swdten bit setting. flag bit setting event clearing event trapr (rcon<15>) trap conflict event por iopuwr (rcon<14>) illegal opcode or uninitialized w register access por cm (rcon<9>) configuration mismatch reset por extr (rcon<7>) mclr reset por swr (rcon<6>) reset instruction por wdto (rcon<4>) wdt time-out pwrsav instruction, por sleep (rcon<3>) pwrsav #sleep instruction por idle (rcon<2>) pwrsav #idle instruction por bor (rcon<1>) por, bor ? por (rcon<0>) por ? dpslp (rcon<10>) pwrsav #sleep instruction with dscon set por note: all reset flag bits may be set or cleared by the user software. register 6-1: rcon: re set control register (1) (continued) reset type clock source determinant por fnosc configuration bits (fnosc<10:8>) bor mclr cosc control bits (osccon<14:12>) wdto swr
pic24f04ka201 family ds39937b-page 54 preliminary ? 2009 microchip technology inc. 6.2 device reset times the reset times for various types of device reset are summarized in table 6-3. note that the system reset signal, sysrst , is released after the por and pwrt delay times expire. the time at which the device actually begins to execute code will also depend on the system oscillator delays, which include the oscillator start-up timer (ost) and the pll lock time. the ost and pll lock times occur in parallel with the applicable sysrst delay times. the fscm delay determines the time at which the fscm begins to monitor the system clock source after the sysrst signal is released. table 6-3: reset delay times for various device resets reset type clock source sysrst delay system clock delay notes por (6) ec t por + t pwrt ? 1, 2 frc, frcdiv t por + t pwrt t frc 1, 2, 3 lprc t por + t pwrt t lprc 1, 2, 3 ecpll t por + t pwrt t lock 1, 2, 4 frcpll t por + t pwrt t frc + t lock 1, 2, 3, 4 xt, hs, sosc t por + t pwrt t ost 1, 2, 5 xtpll, hspll t por + t pwrt t ost + t lock 1, 2, 4, 5 bor ec t pwrt ? 2 frc, frcdiv t pwrt t frc 2, 3 lprc t pwrt t lprc 2, 3 ecpll t pwrt t lock 2, 4 frcpll t pwrt t frc + t lock 2, 3, 4 xt, hs, sosc t pwrt t ost 2, 5 xtpll, hspll t pwrt t frc + t lock 2, 3, 4 all others any clock ? ? none note 1: t por = power-on reset delay. 2: t pwrt = 64 ms nominal if the power-up timer is enabled; otherwise, it is zero. 3: t frc and t lprc = rc oscillator start-up times. 4: t lock = pll lock time. 5: t ost = oscillator start-up timer (ost). a 10-bit counter waits 1024 oscillator periods before releasing oscillator clock to the system. 6: if two-speed start-up is enabled, regardless of the prim ary oscillator selected, the device starts with frc, and in such cases, frc start-up time is valid. note: for detailed operating frequency and timing specifications, see section 29.0 ?electrical characteristics? .
? 2009 microchip technology inc. preliminary ds39937b-page 55 pic24f04ka201 family 6.3 brown-out reset (bor) the pic24f04ka201 family devices implement a bor circuit, which provides the user several configuration and power-saving options. the bor is controlled by the and (boren<1:0>) configura- tion bits (fpor<6:5,1:0>). there are a total of four bor configurations, which are provided in table 6.3.1. the bor threshold is set by the borv<1:0> bits. if bor is enabled (any values of boren<1:0>, except ? 00 ?), any drop of v dd below the set threshold point will reset the device. the chip will remain in bor until v dd rises above threshold. if the power-up timer is enabled, it will be invoked after v dd rises above the threshold; it, then, will keep the chip in reset for an additional time delay, t pwrt , if v dd drops below the threshold while the power-up timer is running. the chip goes back into a bor and the power-up timer will be initialized. once v dd rises above the threshold, the power-up timer will execute the additional time delay. bor and the power-up timer are independently configured. enabling the bor reset does not automatically enable the pwrt. 6.3.1 software enabled bor when boren<1:0> = 01 , the bor can be enabled or disabled by the user in software. this is done with the control bit, sboren (rcon<13>). setting sboren enables the bor to function as previously described. clearing the sboren disables the bor entirely. the sboren bit operates only in this mode; otherwise, it is read as ? 0 ?. placing bor under software control gives the user the additional flexibility of tailoring the application to its environment without having to reprogram the device to change the bor configuration. it also allows the user to tailor the incremental current that the bor con- sumes. while the bor current is typically very small, it may have some impact in low-power applications. 6.3.2 detecting bor when bor is enabled, the bor bit (rcon<1>) is always reset to ? 1 ? on any bor or por event. this makes it difficult to determine if a bor event has occurred just by reading the state of bor alone. a more reliable method is to simultaneously check the state of both por and bor. this assumes that the por and bor bits are reset to ? 0 ? in the software immediately after any por event. if the bor bit is ? 1 ? while por is ? 0 ?, it can be reliably assumed that a bor event has occurred. 6.3.3 disabling bor in sleep mode when boren<1:0> = 10 , bor remains under hard- ware control and operates as previously described. however, whenever the device enters sleep mode, bor is automatically disabled. when the device returns to any other operating mode, bor is automatically re-enabled. this mode allows for applications to recover from brown-out situations, while actively executing code, when the device requires bor protection the most. at the same time, it saves additional power in sleep mode by eliminating the small incremental bor current. 6.3.4 deep sleep bor (dsbor) deep sleep bor is a very low-power bor circuitry. due to low current consumption, accuracy may vary. dsbor occurs anywhere between 1.55v and 1.95v. dsbor is selected in configuration through the borv<1:0> (fpor<6:5>) bits = 00 . dsbor re-arms the por anywhere between 1.55v and 1.95v; however, below 1.55v, the por is asserted. note: even when the bor is under software control, the bor reset voltage level is still set by the borv1:borv0 configuration bits. it can not be changed in software. note: even when the device exits from deep sleep mode, both the por and bor are set.
pic24f04ka201 family ds39937b-page 56 preliminary ? 2009 microchip technology inc. 6.3.5 por and long oscillator start-up times the oscillator start-up circuitry and its associated delay timers are not linked to the device reset delays that occur at power-up. some crystal circuits (especially low-frequency crystals) will have a relatively long start-up time. therefore, one or more of the following conditions is possible after sysrst is released: ? the oscillator circuit has not begun to oscillate. ? the oscillator start-up timer has not expired (if a crystal oscillator is used). ? the pll has not achieved a lock (if pll is used). the device will not begin to execute code until a valid clock source has been released to the system. there- fore, the oscillator and pll start-up delays must be considered when the reset delay time must be known. 6.3.6 fail-safe clock monitor (fscm) and device resets if the fscm is enabled, it will begin to monitor the system clock source when sysrst is released. if a valid clock source is not available at this time, the device will automatically switch to the frc oscillator and the user can switch to the desired crystal oscillator in the trap service routine (tsr). 6.4 special function register reset states most of the special function registers (sfrs) associ- ated with the pic24f cpu and peripherals are reset to a particular value at a device reset. the sfrs are grouped by their peripheral or cpu function and their reset values are specified in each section of this manual. the reset value for each sfr does not depend on the type of reset with the exception of four registers. the reset value for the reset control register, rcon, will depend on the type of device reset. the reset value for the oscillator control register, osccon, will depend on the type of reset and the programmed values of the fnosc bits in flash configuration word (foscsel); see table 6-2. the rcfgcal and nvmcon registers are only affected by a por. 6.5 deep sleep bor (dsbor) deep sleep bor is a very low-power bor circuitry, used when the device is in deep sleep mode. due to low-current consumption, accuracy may vary. the dsbor trip point is around 2.0v. dsbor is enabled by configuring fds = 1 . dslpbor will re-arm the por to ensure the device will reset if v dd drops below the por threshold.
? 2009 microchip technology inc. preliminary ds39937b-page 57 pic24f04ka201 family 7.0 interrupt controller the pic24f interrupt controller reduces the numerous peripheral interrupt request signals to a single interrupt request signal to the cpu. it has the following features: ? up to eight processor exceptions and software traps ? seven user-selectable priority levels ? interrupt vector table (ivt) with up to 118 vectors ? unique vector for each interrupt or exception source ? fixed priority within a specified user priority level ? fixed interrupt entry and return latencies 7.1 interrupt vector (ivt) table the ivt is displayed in figure 7-1. the ivt resides in the program memory, starting at location 000004h. the ivt contains 126 vectors, consisting of eight non-maskable trap vectors, plus, up to 118 sources of interrupt. in general, each interrupt source has its own vector. each interrupt vector contains a 24-bit wide address. the value programmed into each interrupt vector location is the starting address of the associated interrupt service routine (isr). interrupt vectors are prioritized in terms of their natural priority; this is linked to their position in the vector table. all other things being equal, lower addresses have a higher natural priority. for example, the interrupt associated with vector 0 will take priority over interrupts at any other vector address. pic24f04ka201 family devices implement non-maskable traps and unique interrupts; these are summarized in table 7-1 and table 7-2. 7.2 reset sequence a device reset is not a true exception because the interrupt controller is not involved in the reset process. the pic24f devices clear their registers in response to a reset, which forces the program counter (pc) to zero. the microcontroller then begins program execu- tion at location 000000h. the user programs a goto instruction at the reset address, which redirects the program execution to the appropriate start-up routine. figure 7-1: pic24f interrupt vector table note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the interrupt controller, refer to the ?pic24f family reference manual? , section 8. ?interrupts? (ds39707). note: any unimplemented or unused vector locations in the ivt should be programmed with the address of a default interrupt handler routine that contains a reset instruction. reset ? goto instruction 000000h reset ? goto address 000002h reserved 000004h oscillator fail trap vector address error trap vector stack error trap vector math error trap vector reserved reserved reserved interrupt vector 0 000014h interrupt vector 1 ? ? ? interrupt vector 52 00007ch interrupt vector 53 00007eh interrupt vector 54 000080h ? ? ? interrupt vector 116 0000fch interrupt vector 117 0000feh decreasing natural order priority interrupt vector table (ivt) (1) note 1: see table 7-2 for the interrupt vector list.
pic24f04ka201 family ds39937b-page 58 preliminary ? 2009 microchip technology inc. table 7-2: implemented interrupt vectors table 7-1: trap vector details vector number ivt address aivt address trap source 0 000004h 000104h reserved 1 000006h 000106h oscillator failure 2 000008h 000108h address error 3 00000ah 00010ah stack error 4 00000ch 00010ch math error 5 00000eh 00010eh reserved 6 000010h 000110h reserved 7 000012h 000112h reserved interrupt source vector number ivt address aivt address interrupt bit locations flag enable priority adc1 conversion done 13 00002eh 00012eh ifs0<13> iec0<13> ipc3<6:4> comparator event 18 000038h 000138h ifs1<2> iec1<2> ipc4<10:8> ctmu 77 0000aeh 0001aeh ifs4<13> iec4<13> ipc19<6:4> external interrupt 0 0 000014h 000114h ifs0<0> iec0<0> ipc0<2:0> external interrupt 1 20 00003ch 00013ch ifs1<4> iec1<4> ipc5<2:0> external interrupt 2 29 00004eh 00014eh ifs1<13> iec1<13> ipc7<6:4> i2c1 master event 17 000036h 000136h ifs1<1> iec1<1> ipc4<6:4> i2c1 slave event 16 000034h 000134h ifs1<0> iec1<0> ipc4<2:0> input capture1 1 000016h 000116h ifs0<1> iec0<1> ipc0<6:4> input change notification 19 00003ah 00013ah ifs1<3> iec1<3> ipc4<14:12> hlvd high/low-voltage detect 72 0000a4h 0001a4h ifs4<8> iec4<8> ipc17<2:0> nvm ? nvm write complete 15 000032h 000132h ifs0<15> iec0<15> ipc3<14:12> output compare 1 2 000018h 000118h ifs0<2> iec0<2> ipc0<10:8> spi1 error 9 000026h 000126h ifs0<9> iec0<9> ipc2<6:4> spi1 event 10 000028h 000128h ifs0<10> iec0<10> ipc2<10:8> timer1 3 00001ah 00011ah ifs0<3> iec0<3> ipc0<14:12> timer2 7 000022h 000122h ifs0<7> iec0<7> ipc1<14:12> timer3 8 000024h 000124h ifs0<8> iec0<8> ipc2<2:0> uart1 error 65 000096h 000196h ifs4<1> iec4<1> ipc16<6:4> uart1 receiver 11 00002ah 00012ah ifs0<11> iec0<11> ipc2<14:12> uart1 transmitter 12 00002ch 00012ch ifs0<12> iec0<12> ipc3<2:0>
? 2009 microchip technology inc. preliminary ds39937b-page 59 pic24f04ka201 family 7.3 interrupt control and status registers the pic24f04ka201 family of devices implements a total of 23 registers for the interrupt controller: ? intcon1 ? intcon2 ? ifs0, ifs1, ifs3 and ifs4 ? iec0, iec1, iec3 and iec4 ? ipc0 through ipc5, ipc7 and ipc15 through ipc19 ?inttreg global interrupt control functions are controlled from intcon1 and intcon2. intcon1 contains the interrupt nesting disable (nstdis) bit, as well as the control and status flags for the processor trap sources. the intcon2 register controls the external interrupt request signal behavior and the use of the aiv table. the ifsx registers maintain all of the interrupt request flags. each source of interrupt has a status bit, which is set by the respective peripherals, or external signal, and is cleared via software. the iecx registers maintain all of the interrupt enable bits. these control bits are used to individually enable interrupts from the peripherals or external signals. the ipcx registers are used to set the interrupt priority level for each source of interrupt. each user interrupt source can be assigned to one of eight priority levels. the inttreg register contains the associated inter- rupt vector number and the new cpu interrupt priority level, which are latched into the vector number (vecnum<6:0>) and the interrupt level (ilr<3:0>) bit fields in the inttreg register. the new interrupt priority level is the priority of the pending interrupt. the interrupt sources are assigned to the ifsx, iecx and ipcx registers in the same sequence listed in table 7-2. for example, the int0 (external interrupt 0) is depicted as having a vector number and a natural order priority of 0. thus, the int0if status bit is found in ifs0<0>, the int0ie enable bit in iec0<0> and the int0ip<2:0> priority bits in the first position of ipc0 (ipc0<2:0>). although they are not specifically part of the interrupt control hardware, two of the cpu control registers contain bits that control interrupt functionality. the alu status register (sr) contains the ipl<2:0> bits (sr<7:5>). these indicate the current cpu interrupt priority level. the user may change the current cpu priority level by writing to the ipl bits. the corcon register contains the ipl3 bit, which together with ipl<2:0>, also indicates the current cpu priority level. ipl3 is a read-only bit so that the trap events cannot be masked by the user?s software. all interrupt registers are described in register 7-1 through register 7-18, in the following sections.
pic24f04ka201 family ds39937b-page 60 preliminary ? 2009 microchip technology inc. register 7-1: sr: alu status register u-0 u-0 u-0 u-0 u-0 u-0 u-0 r-0, hsc ? ? ? ? ? ? ? dc (1) bit 15 bit 8 r/w-0, hsc r/w-0, hsc r/w-0, hsc r-0, hsc r/w-0, hsc r/w-0, hsc r/w-0, hsc r/w-0, hsc ipl2 (2,3) ipl1 (2,3) ipl0 (2,3) ra (1) n (1) ov (1) z (1) c (1) bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 7-5 ipl<2:0>: cpu interrupt priority level status bits (2,3) 111 = cpu interrupt priority level is 7 (15); user interrupts disabled 110 = cpu interrupt priority level is 6 (14) 101 = cpu interrupt priority level is 5 (13) 100 = cpu interrupt priority level is 4 (12) 011 = cpu interrupt priority level is 3 (11) 010 = cpu interrupt priority level is 2 (10) 001 = cpu interrupt priority level is 1 (9) 000 = cpu interrupt priority level is 0 (8) note 1: see register 3-1 for the description of these bits, which are not dedicated to interrupt control functions. 2: the ipl bits are concatenated with the ipl3 bit (corcon<3>) to form the cpu interrupt priority level. the value in parentheses indicates the interrupt priority level if ipl3 = 1 . 3: the ipl status bits are read-only when nstdis (intcon1<15>) = 1 . note: bit 8 and bits 4 through 0 are described in section 3.0 ?cpu? .
? 2009 microchip technology inc. preliminary ds39937b-page 61 pic24f04ka201 family register 7-2: corcon: cpu control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 r/c-0, hsc r/w-0 u-0 u-0 ? ? ? ?ipl3 (2) psv (1) ? ? bit 7 bit 0 legend: c = clearable bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-4 unimplemented: read as ? 0 ? bit 3 ipl3: cpu interrupt priority level status bit (2) 1 = cpu interrupt priority level is greater than 7 0 = cpu interrupt priority level is 7 or less bit 1-0 unimplemented: read as ? 0 ? note 1: see register 3-1 for the description of this bit, which is not dedicated to interrupt control functions. 2: the ipl3 bit is concatenated with the ipl<2:0> bits (sr<7:5>) to form the cpu interrupt priority level. note: bit 2 is described in section 3.0 ?cpu? .
pic24f04ka201 family ds39937b-page 62 preliminary ? 2009 microchip technology inc. register 7-3: intcon1: in terrupt control register 1 r/w-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 nstdis ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs u-0 ? ? ? matherr addrerr stkerr oscfail ? bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 nstdis: interrupt nesting disable bit 1 = interrupt nesting is disabled 0 = interrupt nesting is enabled bit 14-5 unimplemented: read as ? 0 ? bit 4 matherr: arithmetic error trap status bit 1 = overflow trap has occurred 0 = overflow trap has not occurred bit 3 addrerr: address error trap status bit 1 = address error trap has occurred 0 = address error trap has not occurred bit 2 stkerr: stack error trap status bit 1 = stack error trap has occurred 0 = stack error trap has not occurred bit 1 oscfail: oscillator failure trap status bit 1 = oscillator failure trap has occurred 0 = oscillator failure trap has not occurred bit 0 unimplemented: read as ? 0 ?
? 2009 microchip technology inc. preliminary ds39937b-page 63 pic24f04ka201 family register 7-4: intcon2: in terrupt control register2 r/w-0 r-0, hsc u-0 u-0 u-0 u-0 u-0 u-0 altivt disi ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 ? ? ? ? ? int2ep int1ep int0ep bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 altivt: enable alternate interrupt vector table bit 1 = use alternate interrupt vector table 0 = use standard (default) vector table bit 14 disi: disi instruction status bit 1 = disi instruction is active 0 = disi instruction is not active bit 13-3 unimplemented: read as ? 0 ? bit 2 int2ep: external interrupt 2 edge detect polarity select bit 1 = interrupt on negative edge 0 = interrupt on positive edge bit 1 int1ep: external interrupt 1 edge detect polarity select bit 1 = interrupt on negative edge 0 = interrupt on positive edge bit 0 int0ep: external interrupt 0 edge detect polarity select bit 1 = interrupt on negative edge 0 = interrupt on positive edge
pic24f04ka201 family ds39937b-page 64 preliminary ? 2009 microchip technology inc. register 7-5: ifs0: interrupt flag status register 0 r/w-0, hs u-0 r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs nvmif ? ad1if u1txif u1rxif spi1if spf1if t3if bit 15 bit 8 r/w-0, hs u-0 u-0 u-0 r/w-0, hs r/w-0, hs r/w-0, hs r/w-0, hs t2if ? ? ? t1if oc1if ic1if int0if bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 nvmif: nvm interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 14 unimplemented: read as ? 0 ? bit 13 ad1if: a/d conversion complete interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 12 u1txif: uart1 transmitter interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 11 u1rxif: uart1 receiver interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 10 spi1if: spi1 event interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 9 spf1if: spi1 fault interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 8 t3if: timer3 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 7 t2if: timer2 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 6-4 unimplemented: read as ? 0 ? bit 3 t1if: timer1 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 2 oc1if: output compare channel 1 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 1 ic1if: input capture channel 1 interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 0 int0if: external interrupt 0 flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred
? 2009 microchip technology inc. preliminary ds39937b-page 65 pic24f04ka201 family register 7-6: ifs1: interrupt flag status register 1 u-0 u-0 r/w-0, hs u-0 u-0 u-0 u-0 u-0 ? ?int2if ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0, hs r/w-0, hs r/w-0, hs r/w-0 r/w-0 ? ? ? int1if cnif cmif mi2c1if si2c1if bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 int2if: external interrupt 2 flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 12-5 unimplemented: read as ? 0 ? bit 4 int1if: external interrupt 1 flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 3 cnif: input change notification interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 2 cmif: comparator interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 1 mi2c1if: master i2c1 event interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 0 si2c1if: slave i2c1 event interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred
pic24f04ka201 family ds39937b-page 66 preliminary ? 2009 microchip technology inc. register 7-7: ifs4: interrupt flag status register 4 u-0 u-0 r/w-0, hs u-0 u-0 u-0 u-0 r/w-0, hs ? ?ctmuif ? ? ? ?hlvdif bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0, hs u-0 ? ? ? ? ? ?u1erif ? bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 ctmuif: ctmu interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 12-9 unimplemented: read as ? 0 ? bit 8 hlvdif: high/low-voltage detect interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 7-2 unimplemented: read as ? 0 ? bit 1 u1erif: uart1 error interrupt flag status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 0 unimplemented: read as ? 0 ?
? 2009 microchip technology inc. preliminary ds39937b-page 67 pic24f04ka201 family register 7-8: iec0: interrupt enable control register 0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 nvmie ? ad1ie u1txie u1rxie spi1ie spf1ie t3ie bit 15 bit 8 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 t2ie ? ? ? t1ie oc1ie ic1ie int0ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 nvmie: nvm interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 14 unimplemented: read as ? 0 ? bit 13 ad1ie: a/d conversion complete interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 12 u1txie: uart1 transmitter interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 11 u1rxie: uart1 receiver interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 10 spi1ie: spi1 transfer complete interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 9 spf1ie: spi1 fault interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 8 t3ie: timer3 interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 7 t2ie: timer2 interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 6-4 unimplemented: read as ? 0 ? bit 3 t1ie: timer1 interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 2 oc1ie: output compare channel 1 interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 1 ic1ie: input capture channel 1 interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 0 int0ie: external interrupt 0 enable bit 1 = interrupt request enabled 0 = interrupt request not enabled
pic24f04ka201 family ds39937b-page 68 preliminary ? 2009 microchip technology inc. register 7-9: iec1: interrupt enable control register 1 u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ? ?int2ie ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? int1ie cnie cmie mi2c1ie si2c1ie bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 int2ie: external interrupt 2 enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 12-5 unimplemented: read as ? 0 ? bit 4 int1ie: external interrupt 1 enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 3 cnie: input change notification interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 2 cmie: comparator interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 1 mi2c1ie: master i2c1 event interrupt enable status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred bit 0 si2c1ie: slave i2c1 event interrupt enable status bit 1 = interrupt request has occurred 0 = interrupt request has not occurred
? 2009 microchip technology inc. preliminary ds39937b-page 69 pic24f04ka201 family register 7-10: iec4: interrupt enable control register 4 u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 r/w-0 ? ?ctmuie ? ? ? ?hlvdie bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 u-0 ? ? ? ? ? ?u1erie ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 ctmuie: ctmu interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 12-9 unimplemented: read as ? 0 ? bit 8 hlvdie: high/low-voltage detect interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 7-2 unimplemented: read as ? 0 ? bit 1 u1erie: uart1 error interrupt enable bit 1 = interrupt request enabled 0 = interrupt request not enabled bit 0 unimplemented: read as ? 0 ?
pic24f04ka201 family ds39937b-page 70 preliminary ? 2009 microchip technology inc. register 7-11: ipc0: interrupt priority control register 0 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? t1ip2 t1ip1 t1ip0 ? oc1ip2 oc1ip1 oc1ip0 bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? ic1ip2 ic1ip1 ic1ip0 ? int0ip2 int0ip1 int0ip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 t1ip<2:0>: timer1 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 oc1ip<2:0>: output compare channel 1 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 ic1ip<2:0>: input capture channel 1 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3 unimplemented: read as ? 0 ? bit 2-0 int0ip<2:0>: external interrupt 0 priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
? 2009 microchip technology inc. preliminary ds39937b-page 71 pic24f04ka201 family register 7-12: ipc1: interrupt pr iority control register 1 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? t2ip2 t2ip1 t2ip0 ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 t2ip<2:0>: timer2 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11-0 unimplemented: read as ? 0 ?
pic24f04ka201 family ds39937b-page 72 preliminary ? 2009 microchip technology inc. register 7-13: ipc2: interrupt pr iority control register 2 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? u1rxip2 u1rxip1 u1rxip0 ? spi1ip2 spi1ip1 spi1ip0 bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? spf1ip2 spf1ip1 spf1ip0 ? t3ip2 t3ip1 t3ip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 u1rxip<2:0>: uart1 receiver interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 spi1ip<2:0>: spi1 event interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 spf1ip<2:0>: spi1 fault interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3 unimplemented: read as ? 0 ? bit 2-0 t3ip<2:0>: timer3 interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
? 2009 microchip technology inc. preliminary ds39937b-page 73 pic24f04ka201 family register 7-14: ipc3: interrupt pr iority control register 3 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? nvmip2 nvmip1 nvmip0 ? ? ? ? bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? ad1ip2 ad1ip1 ad1ip0 ? u1txip2 u1txip1 u1txip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 nvmip<2:0>: nvm interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11-7 unimplemented: read as ? 0 ? bit 6-4 ad1ip<2:0>: a/d conversion complete interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3 unimplemented: read as ? 0 ? bit 2-0 u1txip<2:0>: uart1 transmitter interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
pic24f04ka201 family ds39937b-page 74 preliminary ? 2009 microchip technology inc. register 7-15: ipc4: interrupt pr iority control register 4 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? cnip2 cnip1 cnip0 ? cmip2 cmip1 cmip0 bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 r/w-1 r/w-0 r/w-0 ? mi2c1p2 mi2c1p1 mi2c1p0 ? si2c1p2 si2c1p1 si2c1p0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 cnip<2:0>: input change notification interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 11 unimplemented: read as ? 0 ? bit 10-8 cmip<2:0>: comparator interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 7 unimplemented: read as ? 0 ? bit 6-4 mi2c1p<2:0>: master i2c1 event interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3 unimplemented: read as ? 0 ? bit 2-0 si2c1p<2:0>: slave i2c1 event interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
? 2009 microchip technology inc. preliminary ds39937b-page 75 pic24f04ka201 family register 7-16: ipc5: interrupt pr iority control register 5 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? int1ip2 int1ip1 int1ip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-3 unimplemented: read as ? 0 ? bit 2-0 int1ip<2:0>: external interrupt 1 priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled
pic24f04ka201 family ds39937b-page 76 preliminary ? 2009 microchip technology inc. register 7-17: ipc7: interrupt pr iority control register 7 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? int2ip2 int2ip1 int2ip0 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-7 unimplemented: read as ? 0 ? bit 6-4 int2ip<2:0>: external interrupt 2 priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ?
? 2009 microchip technology inc. preliminary ds39937b-page 77 pic24f04ka201 family register 7-18: ipc16: interrupt priority control register 16 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? u1erip2 u1erip1 u1erip0 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-7 unimplemented: read as ? 0 ? bit 6-4 u1erip<2:0>: uart1 error interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ?
pic24f04ka201 family ds39937b-page 78 preliminary ? 2009 microchip technology inc. register 7-19: ipc18: interrupt priority control register 18 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 r/w-1 r/w-0 r/w-0 ? ? ? ? ? hlvdip2 hlvdip1 hlvdip0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-3 unimplemented: read as ? 0 ? bit 2-0 hlvdip<2:0>: high/low-voltage detect interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled register 7-20: ipc19: interrupt priority control register 19 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 r/w-1 r/w-0 r/w-0 u-0 u-0 u-0 u-0 ? ctmuip2 ctmuip1 ctmuip0 ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-7 unimplemented: read as ? 0 ? bit 6-4 ctmuip<2:0>: ctmu interrupt priority bits 111 = interrupt is priority 7 (highest priority interrupt) ? ? ? 001 = interrupt is priority 1 000 = interrupt source is disabled bit 3-0 unimplemented: read as ? 0 ?
? 2009 microchip technology inc. preliminary ds39937b-page 79 pic24f04ka201 family register 7-21: inttreg: interrupt control and status register r-0 u-0 r/w-0 u-0 r-0 r-0 r-0 r-0 cpuirq ?vhold ?ilr<3:0> bit 15 bit 8 u-0 r-0 r-0 r-0 r-0 r-0 r-0 r-0 ? vecnum<6:0> bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 cpuirq: interrupt request from interrupt controller cpu bit 1 = an interrupt request has occurred but has not yet been acknowledged by the cpu (this will happen when the cpu priority is higher than the interrupt priority) 0 = no interrupt request is left unacknowledged bit 14 unimplemented: read as ? 0 ? bit 13 vhold: allows vector number capture and changes what interrupt is stored in vecnum bit 1 = vecnum will contain the value of the highest priority pending interrupt, instead of the current interrupt 0 = vecnum will contain the value of the last acknowledged interrupt (last interrupt that has occurred with higher priority than the cpu, even if other interrupts are pending) bit 12 unimplemented: read as ? 0 ? bit 11-8 ilr<3:0>: new cpu interrupt priority level bits 1111 = cpu interrupt priority level is 15 ? ? ? 0001 = cpu interrupt priority level is 1 0000 = cpu interrupt priority level is 0 bit 7 unimplemented: read as ? 0 ? bit 6-0 vecnum<6:0>: vector number of pending interrupt bits 0111111 = interrupt vector pending is number 135 ? ? ? 0000001 = interrupt vector pending is number 9 0000000 = interrupt vector pending is number 8
pic24f04ka201 family ds39937b-page 80 preliminary ? 2009 microchip technology inc. 7.4 interrupt setup procedures 7.4.1 initialization to configure an interrupt source: 1. set the nstdis control bit (intcon1<15>) if nested interrupts are not desired. 2. select the user-assigned priority level for the interrupt source by writing the control bits in the appropriate ipcx register. the priority level will depend on the specific application and type of interrupt source. if multiple priority levels are not desired, the ipcx register control bits for all enabled interrupt sources may be programmed to the same non-zero value. 3. clear the interrupt flag status bit associated with the peripheral in the associated ifsx register. 4. enable the interrupt source by setting the interrupt enable control bit associated with the source in the appropriate iecx register. 7.4.2 interrupt service routine the method that is used to declare an isr and initialize the ivt with the correct vector address depends on the programming language (i.e., c or assembler) and the language development toolsuite that is used to develop the application. in general, the user must clear the interrupt flag in the appropriate ifsx register for the source of the interrupt that the isr handles. otherwise, the isr will be re-entered immediately after exiting the routine. if the isr is coded in assembly language, it must be terminated using a retfie instruction to unstack the saved pc value, srl value and old cpu priority level. 7.4.3 trap service routine (tsr) a trap service routine (tsr) is coded like an isr, except that the appropriate trap status flag in the intcon1 register must be cleared to avoid re-entry into the tsr. 7.4.4 interrupt disable all user interrupts can be disabled using the following procedure: 1. push the current sr value onto the software stack using the push instruction. 2. force the cpu to priority level 7 by inclusive oring the value oeh with srl. to enable user interrupts, the pop instruction may be used to restore the previous sr value. only user interrupts with a priority level of 7 or less can be disabled. trap sources (level 8-15) cannot be disabled. the disi instruction provides a convenient way to disable interrupts of priority levels 1-6 for a fixed period. level 7 interrupt sources are not disabled by the disi instruction. note: at a device reset, the ipcx registers are initialized, such that all user interrupt sources are assigned to priority level 4.
? 2009 microchip technology inc. preliminary ds39937b-page 81 pic24f04ka201 family 8.0 oscillator configuration the oscillator system for the pic24f04ka201 family of devices has the following features: ? a total of five external and internal oscillator options as clock sources, providing 11 different clock modes. ? on-chip 4x phase locked loop (pll) to boost internal operating frequency on select internal and external oscillator sources. ? software-controllable switching between various clock sources. ? software-controllable postscaler for selective clocking of cpu for system power savings. ? system frequency range declaration bits for ec mode. when using an external clock source, the current consumption is reduced by setting the declaration bits to the expected frequency range. ? a fail-safe clock monitor (fscm) that detects clock failure and permits safe application recovery or shutdown. figure 8-1 provides a simplified diagram of the oscillator system. figure 8-1: pic24f04ka201 family clock diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on oscillator configuration, refer to the ?pic24f family reference manual? , section 38. ?oscillator with 500 khz low-power frc? (ds39726). secondary oscillator soscen enable oscillator sosco sosci clock source option for other modules osci osco primary oscillator xt, hs, ec postscaler clkdiv<10:8> wdt, pwrt, dswdt frcdiv 31 khz (nominal) 8 mhz frc lprc oscillator sosc lprc clock control logic fail-safe clock monitor frc 4 x pll xtpll, hspll ecpll,frcpll 8 mhz 4 mhz cpu peripherals postscaler clkdiv<14:12> clko reference clock generator refo refocon<15:8> oscillator 500 khz lpfrc oscillator
pic24f04ka201 family ds39937b-page 82 preliminary ? 2009 microchip technology inc. 8.1 cpu clocking scheme the system clock source can be provided by one of four sources: ? primary oscillator (posc) on the osci and osco pins ? secondary oscillator (sosc) on the sosci and sosco pins the pic24f04ka201 family devices consist of two types of secondary oscillator: - high-power secondary oscillator - low-power secondary oscillator these can be selected by using the soscsel (fosc<5>) bit. ? fast internal rc (frc) oscillator - 8 mhz frc oscillator - 500 khz lower power frc oscillator ? low-power internal rc (lprc) oscillator the primary oscillator and 8 mhz frc sources have the option of using the internal 4x pll. the frequency of the frc clock source can optionally be reduced by the programmable clock divider. the selected clock source generates the processor and peripheral clock sources. the processor clock source is divided by two to produce the internal instruction cycle clock, f cy . in this docu- ment, the instruction cycle clock is also denoted by f osc /2. the internal instruction cycle clock, f osc /2, can be provided on the osco i/o pin for some operating modes of the primary oscillator. 8.2 initial configuration on por the oscillator source (and operating mode) that is used at a device power-on reset (por) event is selected using configuration bit settings. the oscillator configuration bit settings are located in the configuration registers in the program memory (refer to section 23.1 ?configuration bits? for further details). the primary oscillator configuration bits, poscmd<1:0> (fosc<1:0>), and the initial oscillator select configura- tion bits, fnosc<2:0> (foscsel<2:0>), select the oscillator source that is used at a por. the frc primary oscillator with postscaler (frcdiv) is the default (unpro- grammed) selection. the secondary oscillator, or one of the internal oscillators, may be chosen by programming these bit locations. the ec mode frequency range configuration bits, poscfreq<1:0> (fosc<4:3>), optimize power consumption when running in ec mode. the default configuration is ?frequency range is greater than 8 mhz?. the configuration bits allow users to choose between the various clock modes, shown in table 8-1. 8.2.1 clock switching mode configuration bits the fcksm configuration bits (fosc<7:6>) are used jointly to configure device clock switching and the fscm. clock switching is enabled only when fcksm1 is programmed (? 0 ?). the fscm is enabled only when fcksm<1:0> are both programmed (? 00 ?). table 8-1: configuration bit va lues for clock selection oscillator mode oscillator source poscmd<1:0> fnosc<2:0> note 8 mhz frc oscillator with postscaler (frcdiv) internal 11 111 1, 2 500 mhz frc oscillator with postscaler (lpfrcdiv) internal 11 110 1 low-power rc oscillator (lprc) internal 11 101 1 secondary (timer1) oscillator (sosc) secondary 00 100 1 primary oscillator (hs) with pll module (hspll) primary 10 011 primary oscillator (ec) with pll module (ecpll) primary 00 011 primary oscillator (hs) primary 10 010 primary oscillator (xt) primary 01 010 primary oscillator (ec) primary 00 010 8 mhz frc oscillator with pll module (frcpll) internal 11 001 1 8 mhz frc oscillator (frc) internal 11 000 1 note 1: osco pin function is determined by the osciofnc configuration bit. 2: this is the default oscillator mode for an unprogrammed (erased) device.
? 2009 microchip technology inc. preliminary ds39937b-page 83 pic24f04ka201 family 8.3 control registers the operation of the oscillator is controlled by three special function registers (sfrs): ? osccon ?clkdiv ?osctun the osccon register (register 8-1) is the main con- trol register for the oscillator. it controls clock source switching and allows the monitoring of clock sources. the clock divider register (register 8-2) controls the features associated with doze mode, as well as the postscaler for the frc oscillator. the frc oscillator tune register (register 8-3) allows the user to fine tune the frc oscillator over a range of approximately 12%. each bit increment or decrement changes the factory calibrated frequency of the frc oscillator by a fixed amount. register 8-1: osccon: os cillator control register u-0 r-0, hsc r-0, hsc r-0, hsc u-0 r/w-x (1) r/w-x (1) r/w-x (1) ? cosc2 cosc1 cosc0 ? nosc2 nosc1 nosc0 bit 15 bit 8 r/so-0, hsc u-0 r-0, hsc (2) u-0 r/co-0, hs u-0 r/w-0 r/w-0 clklock ?lock ?cf ? soscen oswen bit 7 bit 0 legend: co = clear only bit so = set only bit hs = hardware settable bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 unimplemented: read as ? 0 ? bit 14-12 cosc<2:0>: current oscillator selection bits 111 = 8 mhz fast rc oscillator with postscaler (frcdiv) 110 = 500 khz low-power fast rc oscillator (frc) with postscaler (lpfrcdiv) 101 = low-power rc oscillator (lprc) 100 = secondary oscillator (sosc) 011 = primary oscillator with pll module (xtpll, hspll, ecpll) 010 = primary oscillator (xt, hs, ec) 001 = 8 mhz frc oscillator with postscaler and pll module (frcpll) 000 = 8 mhz frc oscillator (frc) bit 11 unimplemented: read as ? 0 ? bit 10-8 nosc<2:0>: new oscillator selection bits (1) 111 = 8 mhz fast rc oscillator with postscaler (frcdiv) 110 = 500 khz low-power fast rc oscillator (frc) with postscaler (lpfrcdiv) 101 = low-power rc oscillator (lprc) 100 = secondary oscillator (sosc) 011 = primary oscillator with pll module (xtpll, hspll, ecpll) 010 = primary oscillator (xt, hs, ec) 001 = 8 mhz frc oscillator with postscaler and pll module (frcpll) 000 = 8 mhz frc oscillator (frc) note 1: reset values for these bits are determined by the fnosc configuration bits. 2: also resets to ? 0 ? during any valid clock switch or whenever a non-pll clock mode is selected.
pic24f04ka201 family ds39937b-page 84 preliminary ? 2009 microchip technology inc. bit 7 clklock: clock selection lock enabled bit if fscm is enabled (fcksm1 = 1 ): 1 = clock and pll selections are locked 0 = clock and pll selections are not locked and may be modified by setting the oswen bit if fscm is disabled (fcksm1 = 0 ): clock and pll selections are never locked and may be modified by setting the oswen bit. bit 6 unimplemented: read as ? 0 ? bit 5 lock: pll lock status bit (2) 1 = pll module is in lock or pll module start-up timer is satisfied 0 = pll module is out of lock, pll start-up timer is running or pll is disabled bit 4 unimplemented: read as ? 0 ? bit 3 cf: clock fail detect bit 1 = fscm has detected a clock failure 0 = no clock failure has been detected bit 2 unimplemented: read as ? 0 ? bit 1 soscen: 32 khz secondary oscillator (sosc) enable bit 1 = enable secondary oscillator 0 = disable secondary oscillator bit 0 oswen: oscillator switch enable bit 1 = initiate an oscillator switch to clock source specified by nosc<2:0> bits 0 = oscillator switch is complete register 8-1: osccon: oscillato r control register (continued) note 1: reset values for these bits are determined by the fnosc configuration bits. 2: also resets to ? 0 ? during any valid clock switch or whenever a non-pll clock mode is selected.
? 2009 microchip technology inc. preliminary ds39937b-page 85 pic24f04ka201 family register 8-2: clkdiv: clock divider register r/w-0 r/w-0 r/w-1 r/w-1 r/w-0 r/w-0 r/w-0 r/w-1 roi doze2 doze1 doze0 dozen (1) rcdiv2 rcdiv1 rcdiv0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 roi: recover on interrupt bit 1 = interrupts clear the dozen bit and reset the cpu and peripheral clock ratio to 1:1 0 = interrupts have no effect on the dozen bit bit 14-12 doze<2:0>: cpu and peripheral clock ratio select bits 111 = 1:128 110 = 1:64 101 = 1:32 100 = 1:16 011 = 1:8 010 = 1:4 001 = 1:2 000 = 1:1 bit 11 dozen: doze enable bit (1) 1 = doze<2:0> bits specify the cpu and peripheral clock ratio 0 = cpu and peripheral clock ratio set to 1:1 bit 10-8 rcdiv<2:0>: frc postscaler select bits when osccon (c osc <2 : 0 > ) = 111 : 111 = 31.25 khz (divide by 256) 110 = 125 khz (divide by 64) 101 = 250 khz (divide by 32) 100 = 500 khz (divide by 16) 011 = 1 mhz (divide by 8) 010 = 2 mhz (divide by 4) 001 = 4 mhz (divide by 2) (default) 000 = 8 mhz (divide by 1) w hen osccon (c osc < 2: 0>) = 110 : 111 = 1.95 khz (divide by 256) 110 = 7.81 khz (divide by 64) 101 = 15.62 khz (divide by 32) 100 = 31.25 khz (divide by 16) 011 = 62.5 khz (divide by 8) 010 = 125 khz (divide by 4) 001 = 250 khz (divide by 2) (default) 000 = 500 khz (divide by 1) bit 7-0 unimplemented: read as ? 0 ? note 1: this bit is automatically cleared when the roi bit is set and an interrupt occurs.
pic24f04ka201 family ds39937b-page 86 preliminary ? 2009 microchip technology inc. register 8-3: osctun: frc oscillator tune register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? tun5 (1) tun4 (1) tun3 (1) tun2 (1) tun1 (1) tun0 (1) bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-6 unimplemented: read as ? 0 ? bit 5-0 tun<5:0>: frc oscillator tuning bits (1) 011111 = maximum frequency deviation 011110 000001 000000 = center frequency, oscillator is running at factory calibrated frequency 111111 100001 100000 = minimum frequency deviation note 1: increments or decrements of tun<5:0> may not change the frc frequency in equal steps over the frc tuning range and may not be monotonic.
? 2009 microchip technology inc. preliminary ds39937b-page 87 pic24f04ka201 family 8.4 clock switching operation with few limitations, applications are free to switch between any of the four clock sources (posc, sosc, frc and lprc) under software control and at any time. to limit the possible side effects that could result from this flexibility, pic24f devices have a safeguard lock built into the switching process. 8.4.1 enabling clock switching to enable clock switching, the fcksm1 configuration bit in the fosc configuration register must be programmed to ? 0 ?. (refer to section 23.1 ?configuration bits? for further details.) if the fcksm1 configuration bit is unpro- grammed (? 1 ?), the clock switching function and fscm function are disabled. this is the default setting. the noscx control bits (osccon<10:8>) do not control the clock selection when clock switching is disabled. however, the coscx bits (osccon<14:12>) will reflect the clock source selected by the fnoscx configuration bits. the oswen control bit (osccon<0>) has no effect when clock switching is disabled; it is held at ? 0 ? at all times. 8.4.2 oscillator switching sequence at a minimum, performing a clock switch requires this basic sequence: 1. if desired, read the coscx bits (osccon<14:12>), to determine the current oscillator source. 2. perform the unlock sequence to allow a write to the osccon register high byte. 3. write the appropriate value to the noscx bits (osccon<10:8>) for the new oscillator source. 4. perform the unlock sequence to allow a write to the osccon register low byte. 5. set the oswen bit to initiate the oscillator switch. once the basic sequence is completed, the system clock hardware responds automatically as follows: 1. the clock switching hardware compares the coscx bits with the new value of the noscx bits. if they are the same, then the clock switch is a redundant operation. in this case, the oswen bit is cleared automatically and the clock switch is aborted. 2. if a valid clock switch has been initiated, the lock (osccon<5>) and cf (osccon<3>) bits are cleared. 3. the new oscillator is turned on by the hardware if it is not currently running. if a crystal oscillator must be turned on, the hardware will wait until the ost expires. if the new source is using the pll, then the hardware waits until a pll lock is detected (lock = 1 ). 4. the hardware waits for 10 clock cycles from the new clock source and then performs the clock switch. 5. the hardware clears the oswen bit to indicate a successful clock transition. in addition, the noscx bits value is transferred to the coscx bits. 6. the old clock source is turned off at this time, with the exception of lprc (if wdt or fscm with lprc as a clock source is enabled) or sosc (if soscen remains enabled). note: the primary oscillator mode has three different submodes (xt, hs and ec), which are determined by the poscmdx configuration bits. while an application can switch to and from primary oscillator mode in software, it cannot switch between the different primary submodes without reprogramming the device. note 1: the processor will continue to execute code throughout the clock switching sequence. timing-sensitive code should not be executed during this time. 2: direct clock switches between any primary oscillator mode with pll and frcpll mode are not permitted. this applies to clock switches in either direction. in these instances, the application must switch to frc mode as a transition clock source between the two pll modes.
pic24f04ka201 family ds39937b-page 88 preliminary ? 2009 microchip technology inc. the following code sequence for a clock switch is recommended: 1. disable interrupts during the osccon register unlock and write sequence. 2. execute the unlock sequence for the osccon high byte by writing 78h and 9ah to osccon<15:8> in two back-to-back instructions. 3. write new oscillator source to the noscx bits in the instruction immediately following the unlock sequence. 4. execute the unlock sequence for the osccon low byte by writing 46h and 57h to osccon<7:0> in two back-to-back instructions. 5. set the oswen bit in the instruction immediately following the unlock sequence. 6. continue to execute code that is not clock-sensitive (optional). 7. invoke an appropriate amount of software delay (cycle counting) to allow the selected oscillator and/or pll to start and stabilize. 8. check to see if oswen is ? 0 ?. if it is, the switch was successful. if oswen is still set, then check the lock bit to determine the cause of failure. the core sequence for unlocking the osccon register and initiating a clock switch is provided in example 8-1. example 8-1: basic code sequence for clock switching 8.5 reference clock output in addition to the clko output (f osc /2) available in certain oscillator modes, the device clock in the pic24f04ka201 family devices can also be configured to provide a reference clock output signal to a port pin. this feature is available in all oscillator configurations and allows the user to select a greater range of clock submultiples to drive external devices in the application. this reference clock output is controlled by the refocon register (register 8-4). setting the roen bit (refocon<15>) makes the clock signal available on the refo pin. the rodiv bits (refocon<11:8>) enable the selection of 16 different clock divider options. the rosslp and rosel bits (refocon<13:12>) control the availability of the reference output during sleep mode. the rosel bit determines if the oscillator on osc1 and osc2, or the current system clock source, is used for the reference clock output. the rosslp bit determines if the reference source is available on refo when the device is in sleep mode. to use the reference clock output in sleep mode, both the rosslp and rosel bits must be set. the device clock must also be configured for one of the primary modes (ec, hs or xt); otherwise, if the rosel bit is not also set, the oscillator on osc1 and osc2 will be powered down when the device enters sleep mode. clearing the rosel bit allows the reference output frequency to change as the system clock changes during any clock switches. ;place the new oscillator selection in w0 ;oscconh (high byte) unlock sequence mov #oscconh, w1 mov #0x78, w2 mov #0x9a, w3 mov.b w2, [w1] mov.b w3, [w1] ;set new oscillator selection mov.b wreg, oscconh ;oscconl (low byte) unlock sequence mov #oscconl, w1 mov #0x46, w2 mov #0x57, w3 mov.b w2, [w1] mov.b w3, [w1] ;start oscillator switch operation bset osccon,#0
? 2009 microchip technology inc. preliminary ds39937b-page 89 pic24f04ka201 family register 8-4: refocon: reference oscillator control register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 roen ? rosslp rosel rodiv3 rodiv2 rodiv1 rodiv0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 roen: reference oscillator output enable bit 1 = reference oscillator enabled on refo pin 0 = reference oscillator disabled bit 14 unimplemented: read as ? 0 ? bit 13 rosslp: reference oscillator output stop in sleep bit 1 = reference oscillator continues to run in sleep 0 = reference oscillator is disabled in sleep bit 12 rosel: reference oscillator source select bit 1 = primary oscillator used as the base clock (1) 0 = system clock used as the base clock; base clock reflects any clock switching of the device bit 11-8 rodiv3:rodiv0: reference oscillator divisor select bits 1111 = base clock value divided by 32,768 1110 = base clock value divided by 16,384 1101 = base clock value divided by 8,192 1100 = base clock value divided by 4,096 1011 = base clock value divided by 2,048 1010 = base clock value divided by 1,024 1001 = base clock value divided by 512 1000 = base clock value divided by 256 0111 = base clock value divided by 128 0110 = base clock value divided by 64 0101 = base clock value divided by 32 0100 = base clock value divided by 16 0011 = base clock value divided by 8 0010 = base clock value divided by 4 0001 = base clock value divided by 2 0000 = base clock value bit 7-0 unimplemented: read as ? 0 ? note 1: the crystal oscillator must be enabled using the fosc<2:0> bits; the crystal maintains the operation in sleep mode.
pic24f04ka201 family ds39937b-page 90 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 91 pic24f04ka201 family 9.0 power-saving features the pic24f04ka201 family of devices provides the ability to manage power consumption by selectively managing clocking to the cpu and the peripherals. in general, a lower clock frequency and a reduction in the number of circuits being clocked constitutes lower consumed power. all pic24f devices manage power consumption in four different ways: ? clock frequency ? instruction-based sleep, idle and deep sleep modes ? software controlled doze mode ? selective peripheral control in software combinations of these methods can be used to selectively tailor an application?s power consumption, while still maintaining critical application features, such as timing-sensitive communications. 9.1 clock frequency and clock switching pic24f devices allow for a wide range of clock frequencies to be selected under application control. if the system clock configuratio n is not locked, users can choose low-power or high-precision oscillators by simply changing the nosc bits. the process of changing a system clock during operation, as well as limitations to the process, are discussed in more detail in section 8.0 ?oscillator configuration? . 9.2 instruction-based power-saving modes pic24f devices have two special power-saving modes that are entered through the execution of a special pwrsav instruction. sleep mode stops clock operation and halts all code execution; idle mode halts the cpu and code execution, but allows peripheral modules to continue operation. deep sleep mode stops clock operation, code execution and all peripherals except dswdt. it also freezes i/o states and removes power to sram and flash memory. the assembly syntax of the pwrsav instruction is shown in example 9-1. sleep and idle modes can be exited as a result of an enabled interrupt, wdt time-out or a device reset. when the device exits these modes, it is said to ?wake-up?. 9.2.1 sleep mode sleep mode has these features: ? the system clock source is shut down. if an on-chip oscillator is used, it is turned off. ? the device current consumption will be reduced to a minimum provided that no i/o pin is sourcing current. ? the i/o pin directions and states are frozen. ? the fail-safe clock monitor does not operate during sleep mode since the system clock source is disabled. ? the lprc clock will continue to run in sleep mode if the wdt with lprc as a clock source is enabled. ? the wdt, if enabled, is automatically cleared prior to entering sleep mode. ? some device features or peripherals may continue to operate in sleep mode. this includes items such as the input change notification on the i/o ports, or peripherals that use an external clock input. any peripheral that requires the system clock source for its operation will be disabled in sleep mode. the device will wake-up from sleep mode on any of these events: ? on any interrupt source that is individually enabled ? on any form of device reset ? on a wdt time-out on wake-up from sleep, the processor will restart with the same clock source that was active when sleep mode was entered. example 9-1: pwrsav instruction syntax note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information, refer to the ?pic24f family reference manual? , section 39. ?power-saving features with deep sleep? (ds39727). note: sleep_mode and idle_mode are con- stants defined in the assembler include file for the selected device. pwrsav #sleep_mode ; put the device into sleep mode pwrsav #idle_mode ; put the device into idle mode bset dscon, #dsen ; enable deep sleep pwrsav #sleep_mode ; put the device into deep sleep mode
pic24f04ka201 family ds39937b-page 92 preliminary ? 2009 microchip technology inc. 9.2.2 idle mode idle mode has these features: ? the cpu will stop executing instructions. ? the wdt is automatically cleared. ? the system clock source remains active. by default, all peripheral modules continue to operate normally from the system clock source, but can also be selectively disabled (see section 9.4 ?selective peripheral module control? ). ? if the wdt or fscm is enabled, the lprc will also remain active. the device will wake from idle mode on any of these events: ? any interrupt that is individually enabled ? any device reset ? a wdt time-out on wake-up from idle, the clock is reapplied to the cpu and instruction execution begins immediately, starting with the instruction following the pwrsav instruction or the first instruction in the isr. 9.2.3 interrupts coincident with power save instructions any interrupt that coincides with the execution of a pwrsav instruction will be held off until entry into sleep or idle mode has completed. the device will then wake-up from sleep or idle mode. 9.2.4 deep sleep mode in pic24f04ka201 family devices, deep sleep mode is intended to provide the lowest levels of power consumption available, without requiring the use of external switches to completely remove all power from the device. entry into deep sleep mode is completely under software control. exit from deep sleep mode can be triggered from any of the following events: ? por event ?mclr event ? external interrupt 0 ? deep sleep watchdog timer (dswdt) time-out the device has a dedicated deep sleep brown-out reset (dsbor) and a deep sleep watchdog timer reset (dswdt) for monitoring voltage and time-out events. the dsbor and dswdt are independent of the standard bor and wdt used with other power-managed modes (sleep, idle and doze). 9.2.4.1 entering deep sleep mode deep sleep mode is entered by setting the dsen bit in the dscon register, and then executing a sleep instruction ( pwrsav #sleep_mode ) within one instruc- tion cycle to minimize the chance that deep sleep will be spuriously entered. if the pwrsav command is not given within one instruc- tion cycle, the dsen bit will be cleared by the hardware and must be set again by the software before entering deep sleep mode. the dsen bit is also automatically cleared when exiting the deep sleep mode. the sequence to enter deep sleep mode is: 1. if the application requires the deep sleep wdt, enable it and configure its clock source (see section 9.2.4.5 ?deep sleep wdt? for details). 2. if the application requires deep sleep bor, enable it by programming the dsboren configuration bit (fds<6>). 3. if needed, save any critical application context data by writing it to the dsgpr0 and dsgpr1 registers (optional). 4. enable deep sleep mode by setting the dsen bit (dscon<15>). 5. enter deep sleep mode by issuing 3 nop commands and then a pwrsav #0 instruction. any time the dsen bit is set, all bits in the dswsrc register will be automatically cleared. 9.2.4.2 exiting deep sleep mode deep sleep mode exits on any one of the following events: ? por event on v dd supply. if there is no dsbor circuit to re-arm the v dd supply por circuit, the external v dd supply must be lowered to the natural arming voltage of the por circuit. ? dswdt time-out. when the dswdt timer times out, the device exits deep sleep. ? assertion (? 0 ?) of the mclr pin. ? assertion of the int0 pin (if the interrupt was enabled before deep sleep mode was entered). the polarity configuration is used to determine the assertion level (? 0 ? or ? 1 ?) of the pin that will cause an exit from deep sleep mode. exiting from deep sleep mode requires a change on the int0 pin while in deep sleep mode. note: to re-enter deep sleep after a deep sleep wake-up, allow a delay of at least 3 t cy after clearing the release bit.
? 2009 microchip technology inc. preliminary ds39937b-page 93 pic24f04ka201 family exiting deep sleep mode generally does not retain the state of the device and is equivalent to a power-on reset (por) of the device. exceptions to this include the dsgprx registers and dswsrc. wake-up events that occur from the time deep sleep exits until the time the por sequence completes are ignored, and are not be captured in the dswake register. the sequence for exiting deep sleep mode is: 1. after a wake-up event, the device exits deep sleep and performs a por. the dsen bit is cleared automatically. code execution resumes at the reset vector. 2. to determine if the device exited deep sleep, read the deep sleep bit, dpslp (rcon<10>). this bit will be set if there was an exit from deep sleep mode. if the bit is set, clear it. 3. determine the wake-up source by reading the dswake register. 4. determine if a dsbor event occurred during deep sleep mode by reading the dsbor bit (dscon<1>). 5. if application context data has been saved, read it back from the dsgpr0 and dsgpr1 registers. 6. clear the release bit (dscon<0>). 9.2.4.3 saving context data with the dsgpr0/dsgpr1 registers as exiting deep sleep mode causes a por, most special function registers reset to their default por values. in addition, because v ddcore power is not supplied in deep sleep mode, information in data ram may be lost when exiting this mode. applications which require critical data to be saved prior to deep sleep may use the deep sleep general purpose registers, dsgpr0 and dsgpr1, or data eeprom (if available). unlike other sfrs, the con- tents of these registers are preserved while the device is in deep sleep mode. after exiting deep sleep, software can restore the data by reading the registers and clearing the release bit (dscon<0>). 9.2.4.4 i/o pins during deep sleep during deep sleep, the general purpose i/o pins retain their previous states and the secondary oscillator (sosc) will remain running, if enabled. pins that are configured as inputs (tris bit set) prior to entry into deep sleep remain high-impedance during deep sleep. pins that are configured as outputs (tris bit clear) prior to entry into deep sleep remain as output pins during deep sleep. while in this mode, they con- tinue to drive the output level determined by their corresponding lat bit at the time of entry into deep sleep. once the device wakes back up, all i/o pins continue to maintain their previous states, even after the device has finished the por sequence and is executing appli- cation code again. pins configured as inputs during deep sleep remain high-impedance and pins config- ured as outputs continue to drive their previous value. after waking up, the tris and lat registers, and the soscen bit (osccon<1>) are reset. if firmware modifies any of these bits or registers, the i/o will not immediately go to the newly configured states. once the firmware clears the release bit (dscon<0>) the i/o pins are ?released?. this causes the i/o pins to take the states configured by their respective tris and lat bit values. this means that keeping the sosc running after waking up requires the soscen bit to be set before clearing release. if the deep sleep bor (dsbor) is enabled, and a dsbor or a true por event occurs during deep sleep, the i/o pins will be immediately released similar to clearing the release bit. all previous state infor- mation will be lost, including the general purpose dsgpr0 and dsgpr1 contents. if a mclr reset event occurs during deep sleep, the dsgprx, dscon and dswake registers will remain valid and the release bit will remain set. the state of the sosc also will be retained. the i/o pins, however, will be reset to their mclr reset state. since release is still set, changes to the soscen bit (osccon<1>) cannot take effect until the release bit is cleared. in all other deep sleep wake-up cases, application firmware must clear the release bit in order to reconfigure the i/o pins. note: any interrupt pending when entering deep sleep mode is cleared,
pic24f04ka201 family ds39937b-page 94 preliminary ? 2009 microchip technology inc. 9.2.4.5 deep sleep wdt to enable the dswdt in deep sleep mode, program the configuration bit, dswdten (fds<7>). the device watchdog timer (wdt) need not be enabled for the dswdt to function. entry into deep sleep mode automatically resets the dswdt. the dswdt clock source is selected by the dswdtosc configuration bit (fds<4>). the postscaler options are programmed by the dswdtps<3:0> configuration bits (fds<3:0>). the minimum time-out period that can be achieved is 2.1 ms and the maximum is 25.7 days. for more details on the fds configuration register and dswdt configuration options, refer to section 23.0 ?special features? . 9.2.4.6 switching clocks in deep sleep mode the dswdt may run from either sosc or the lprc clock source. this allows the dswdt to run without requiring both the lprc and sosc to be enabled together, reducing power consumption. under certain circumstances, it is possible for the dswdt clock source to be off when entering deep sleep mode. in this case, the clock source is turned on automatically (if dswdt is enabled), without the need for software intervention. however, this can cause a delay in the start of the dswdt counters. in order to avoid this delay when using sosc as a clock source, the application can activate sosc prior to entering deep sleep mode. 9.2.4.7 checking and clearing the status of deep sleep upon entry into deep sleep mode, the status bit, dpslp (rcon<10>), becomes set and must be cleared by the software. on power-up, the software should read this status bit to determine if the reset was due to an exit from deep sleep mode and clear the bit if it is set. of the four possible combinations of dpslp and por bit states, three cases can be considered: ? both the dpslp and por bits are cleared. in this case, the reset was due to some event other than a deep sleep mode exit. ? the dpslp bit is clear, but the por bit is set. this is a normal por. ? both the dpslp and por bits are set. this means that deep sleep mode was entered, the device was powered down and deep sleep mode was exited. 9.2.4.8 power-on resets ( pors ) v dd voltage is monitored to produce pors. since exit- ing from deep sleep functionally looks like a por, the technique described in section 9.2.4.7 ?checking and clearing the status of deep sleep? should be used to distinguish between deep sleep and a true por event. when a true por occurs, the entire device including all deep sleep logic, (deep sleep registers, dswdt, etc.) is reset. 9.2.4.9 summary of deep sleep sequence to review, these are the necessary steps involved in invoking and exiting deep sleep mode: 1. device exits reset and begins to execute its application code. 2. if dswdt functionality is required, program the appropriate configuration bit. 3. select the appropriate clock(s) for the dswdt (optional). 4. enable and configure the dswdt (optional). 5. write context data to the dsgprx registers (optional). 6. enable the int0 interrupt (optional). 7. set the dsen bit in the dscon register. 8. enter deep sleep by issuing a pwrsv #sleep_mode command. 9. device exits deep sleep when a wake-up event occurs. 10. the dsen bit is automatically cleared. 11. read and clear the dpslp status bit in rcon, and the dswake status bits. 12. read the dsgprx registers (optional). 13. once all state related configurations are complete, clear the release bit. 14. application resumes normal operation.
? 2009 microchip technology inc. preliminary ds39937b-page 95 pic24f04ka201 family register 9-1: dscon: deep sleep control register (1) r/w-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 dsen ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/c-0, hs ? ? ? ? ? ? dsbor (2) release bit 7 bit 0 legend: c = clearable bit hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 dsen: deep sleep enable bit 1 = enters deep sleep on execution of pwrsav #0 0 = enters normal sleep on execution of pwrsav #0 bit 14-2 unimplemented: read as ? 0 ? bit 1 dsbor: deep sleep bor event bit (2) 1 = the dsbor was active and a bor event was detected during deep sleep 0 = the dsbor was not active, or was active but did not detect a bor event during deep sleep bit 0 release: i/o pin state release bit 1 = upon waking from deep sleep, i/o pins maintain their states previous to deep sleep entry 0 = release i/o pins from their state previous to deep sleep entry, and allow their respective tris and lat bits to control their states note 1: all register bits are reset only in the case of a por event outside of deep sleep mode. 2: unlike all other events, a deep sleep bor event will not cause a wake-up from deep sleep; this re-arms por.
pic24f04ka201 family ds39937b-page 96 preliminary ? 2009 microchip technology inc. register 9-2: dswsrc: deep sleep wake-up source register (1) u-0 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0, hs ? ? ? ? ? ? ?dsint0 bit 15 bit 8 r/w-0, hs u-0 u-0 r/w-0, hs u-0 r/w-0, hs u-0 r/w-0, hs dsflt ? ?dswdt ?dsmclr ? dspor (2,3) bit 7 bit 0 legend: hs = hardware settable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 dsint0: interrupt-on-change bit 1 = interrupt-on-change was asserted during deep sleep 0 = interrupt-on-change was not asserted during deep sleep bit 7 dsflt: deep sleep fault detected bit 1 = a fault occurred during deep sleep, and some deep sleep configuration settings may have been corrupted 0 = no fault was detected during deep sleep bit 6-5 unimplemented: read as ? 0 ? bit 4 dswdt: deep sleep watchdog timer time-out bit 1 = the deep sleep watchdog timer timed out during deep sleep 0 = the deep sleep watchdog timer did not time out during deep sleep bit 3 unimplemented: read as ? 0 ? bit 2 dsmclr: mclr event bit 1 = the mclr pin was active and was asserted during deep sleep 0 = the mclr pin was not active, or was active, but not asserted during deep sleep bit 1 unimplemented: read as ? 0 ? bit 0 dspor: power-on reset event bit (2,3) 1 = the v dd supply por circuit was active and a por event was detected 0 = the v dd supply por circuit was not active, or was active but did not detect a por event note 1: all register bits are cleared when the dscon bit is set. 2: all register bits are reset only in the case of a por event outside deep sleep mode, except the dspor bit, which does not reset on a por event that is caused due to a deep sleep exit. 3: unlike the other bits in this register, this bit can be set outside of deep sleep.
? 2009 microchip technology inc. preliminary ds39937b-page 97 pic24f04ka201 family 9.2.5 interrupts coincident with power save instructions any interrupt that coincides with the execution of a pwrsav instruction will be held off until entry into sleep or idle mode is completed. the device will then wake-up from sleep or idle mode. 9.3 doze mode generally, changing clock speed and invoking one of the power-saving modes are the preferred strategies for reducing power consumption. there may be circumstances, however, where this is not practical. for example, it may be necessary for an application to maintain uninterrupted synchronous communication, even while it is doing nothing else. reducing system clock speed may introduce communication errors, while using a power-saving mode may stop communications completely. doze mode is a simple and effective alternative method to reduce power consumption while the device is still executing code. in this mode, the system clock continues to operate from the same source and at the same speed. peripheral modules continue to be clocked at the same speed while the cpu clock speed is reduced. synchronization between the two clock domains is maintained, allowing the peripherals to access the sfrs while the cpu executes code at a slower rate. doze mode is enabled by setting the dozen bit (clkdiv<11>). the ratio between peripheral and core clock speed is determined by the doze<2:0> bits (clkdiv<14:12>). there are eight possible configurations, from 1:1 to 1:128, with 1:1 being the default. it is also possible to use doze mode to selectively reduce power consumption in event driven applications. this allows clock-sensitive functions, such as synchronous communications, to continue without interruption while the cpu idles, waiting for something to invoke an interrupt routine. enabling the automatic return to full-speed cpu operation on interrupts is enabled by set- ting the roi bit (clkdiv<15>). by default, interrupt events have no effect on doze mode operation. 9.4 selective peripheral module control idle and doze modes allow users to substantially reduce power consumption by slowing or stopping the cpu clock. even so, peripheral modules still remain clocked, and thus, consume power. there may be cases where the application needs what these modes do not provide: the allocation of power resources to cpu processing with minimal power consumption from the peripherals. pic24f devices address this requirement by allowing peripheral modules to be selectively disabled, reducing or eliminating their power consumption. this can be done with two control bits: ? the peripheral enable bit, generically named, ?xxxen?, located in the module?s main control sfr. ? the peripheral module disable (pmd) bit, generically named, ?xxxmd?, located in one of the pmd control registers. both bits have similar functions in enabling or disabling its associated module. setting the pmd bit for a module disables all clock sources to that module, reducing its power consumption to an absolute minimum. in this state, the control and status registers associated with the peripheral will also be disabled, so writes to those registers will have no effect and read values will be invalid. many peripheral modules have a corresponding pmd bit. in contrast, disabling a module by clearing its xxxen bit disables its functionality, but leaves its registers available to be read and written to. power consumption is reduced, but not by as much as the pmd bits are used. most peripheral modules have an enable bit; exceptions include capture and compare modules. to achieve more selective power savings, peripheral modules can also be selectively disabled when the device enters idle mode. this is done through the control bit of the generic name format, ?xxxidl?. by default, all modules that can operate during idle mode will do so. using the disable on idle feature disables the module while in idle mode, allowing further reduction of power consumption during idle mode, enhancing power savings for extremely critical power applications.
pic24f04ka201 family ds39937b-page 98 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 99 pic24f04ka201 family 10.0 i/o ports all of the device pins (except v dd and v ss ) are shared between the peripherals and the parallel i/o ports. all i/o input ports feature schmitt trigger inputs for improved noise immunity. 10.1 parallel i/o (pio) ports a parallel i/o port that shares a pin with a peripheral is, in general, subservient to the peripheral. the peripheral?s output buffer data and control signals are provided to a pair of multiplexers. the multiplexers select whether the peripheral or the associated port has ownership of the output data and control signals of the i/o pin. the logic also prevents ?loop through?, in which a port?s digital output can drive the input of a peripheral that shares the same pin. figure 10-1 displays how ports are shared with other peripherals and the associated i/o pin to which they are connected. when a peripheral is enabled and the peripheral is actively driving an associated pin, the use of the pin as a general purpose output pin is disabled. the i/o pin may be read, but the output driver for the parallel port bit will be disabled. if a peripheral is enabled, but the peripheral is not actively driving a pin, that pin may be driven by a port. all port pins have three registers directly associated with their operation as digital i/o. the data direction register (trisx) determines whether the pin is an input or an output. if the data direction bit is a ? 1 ?, then the pin is an input. all port pins are defined as inputs after a reset. reads from the data latch register (latx), read the latch. writes to the latch, write the latch. reads from the port (portx), read the port pins, while writes to the port pins, write the latch. any bit and its associated data and control registers that are not valid for a particular device will be disabled. that means the corresponding latx and trisx registers and the port pin will read as zeros. when a pin is shared with another peripheral or function that is defined as an input only, it is nevertheless regarded as a dedicated port because there is no other competing source of outputs. figure 10-1: block diag ram of a typical shared port structure note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the i/o ports, refer to the ?pic24f family refer- ence manual? , section 12. ?i/o ports with peripheral pin select (pps)? (ds39711). note that the pic24f04ka201 family devices do not support peripheral pin select features. note: the i/o pins retain their state during deep sleep. they will retain this state at wake-up until the software restore bit (release) is cleared. q d ck wr lat + tris latch i/o pin wr port data bus q d ck data latch read port read tris 1 0 1 0 wr tris peripheral output data peripheral input data i/o peripheral module peripheral output enable pio module output multiplexers output data input data peripheral module enable read lat output enable
pic24f04ka201 family ds39937b-page 100 preliminary ? 2009 microchip technology inc. 10.1.1 open-drain configuration in addition to the port, lat and tris registers for data control, each port pin can also be individually configured for either digital or open-drain output. this is controlled by the open-drain control register, odcx, associated with each port. setting any of the bits configures the corresponding pin to act as an open-drain output. the maximum open-drain voltage allowed is the same as the maximum v ih specification. 10.2 configuring analog port pins the use of the ad1pcfg and tris registers control the operation of the a/d port pins. the port pins that are desired as analog inputs must have their corresponding tris bit set (input). if the tris bit is cleared (output), the digital output level (v oh or v ol ) will be converted. when reading the port register, all pins configured as analog input channels will read as cleared (a low level). analog levels on any pin that is defined as a digital input (including the anx pins) may cause the input buffer to consume current that exceeds the device specifications. 10.2.1 i/o port write/read timing one instruction cycle is required between a port direction change or port write operation and a read operation of the same port. typically, this instruction would be a nop . 10.3 input change notification the input change notification function of the i/o ports allows the pic24f04ka201 family of devices to generate interrupt requests to the processor in response to a change of state on selected input pins. this feature is capable of detecting input change of states even in sleep mode, when the clocks are disabled. depending on the device pin count, there are up to 17 external signals (11 on 14-pin devices) that may be selected (enabled) for generating an interrupt request on a change of state. there are six control registers associated with the cn module. the cnen1 and cnen2 registers contain the interrupt enable control bits for each of the cn input pins. setting any of these bits enables a cn interrupt for the corresponding pins. each cn pin also has a weak pull-up/pull-down connected to it. the pull-ups act as a current source that is connected to the pin and the pull-downs act as a current sink to eliminate the need for external resistors when push button or keypad devices are connected. on any pin, only the pull-up resistor or the pull-down resistor should be enabled, but not both of them. if the push button or the keypad is connected to v dd , enable the pull-down, or if they are connected to v ss , enable the pull-up resistors. the pull-ups are enabled separately using the cnpu1 and cnpu2 registers, which contain the control bits for each of the cn pins. setting any of the control bits enables the weak pull-ups for the corresponding pins. the pull-downs are enabled separately using the cnpd1 and cnpd2 registers, which contain the control bits for each of the cn pins. setting any of the control bits enables the weak pull-downs for the corresponding pins. when the internal pull-up is selected, the pin uses v dd as the pull-up source voltage. when the internal pull-down is selected, the pins are pulled down to v ss by an internal resistor. make sure that there is no external pull-up source/pull-down sink when the internal pull-ups/pull-downs are enabled. example 10-1: port write/read example note: pull-ups and pull-downs on change notification pins should always be disabled whenever the port pin is configured as a digital output. mov 0xff00, w0; //configure portb<15:8> as inputs and portb<7:0> as outputs mov w0, trisbb; nop; //delay 1 cycle btss portb, #13; //next instruction equivalent ?c? code trisb = 0xff00; //configure portb<15:8> as inputs and portb<7:0> as outputs nop(); //delay 1 cycle if(portbbits.rb13 == 1) // execute following code if portb pin 13 is set. { }
? 2009 microchip technology inc. preliminary ds39937b-page 101 pic24f04ka201 family 11.0 timer1 the timer1 module is a 16-bit timer which can operate as a free-running, interval timer/counter. timer1 can operate in three modes: ?16-bit timer ? 16-bit synchronous counter ? 16-bit asynchronous counter timer1 also supports these features: ? timer gate operation ? selectable prescaler settings ? timer operation during cpu idle and sleep modes ? interrupt on 16-bit period register match or falling edge of external gate signal figure 11-1 presents a block diagram of the 16-bit timer1 module. to configure timer1 for operation: 1. set the ton bit (= 1 ). 2. select the timer prescaler ratio using the tckps<1:0> bits. 3. set the clock and gating modes using the tcs and tgate bits. 4. set or clear the tsync bit to configure synchronous or asynchronous operation. 5. load the timer period value into the pr1 register. 6. if interrupts are required, set the interrupt enable bit, t1ie. use the priority bits, t1ip<2:0>, to set the interrupt priority. figure 11-1: 16-bit time r1 module block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on timers, refer to the ?pic24f family reference manual? , section 14. ?timers? (ds39704). ton sync sosci sosco/ pr1 set t1if equal comparator tmr1 reset soscen 1 0 tsync q q d ck tckps<1:0> prescaler 1, 8, 64, 256 2 tgate t cy 1 0 t1ck tcs 1x 01 tgate 00 gate sync
pic24f04ka201 family ds39937b-page 102 preliminary ? 2009 microchip technology inc. register 11-1: t1con: timer1 control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ton ?tsidl ? ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 u-0 ? tgate tckps1 tckps0 ?tsynctcs ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ton: timer1 on bit 1 = starts 16-bit timer1 0 = stops 16-bit timer1 bit 14 unimplemented: read as ? 0 ? bit 13 tsidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-7 unimplemented: read as ? 0 ? bit 6 tgate: timer1 gated time accumulation enable bit when tcs = 1 : this bit is ignored. when tcs = 0 : 1 = gated time accumulation enabled 0 = gated time accumulation disabled bit 5-4 tckps<1:0>: timer1 input clock prescale select bits 11 = 1:256 10 = 1:64 01 = 1:8 00 = 1:1 bit 3 unimplemented: read as ? 0 ? bit 2 tsync: timer1 external clock input synchronization select bit when tcs = 1 : 1 = synchronize external clock input 0 = do not synchronize external clock input when tcs = 0 : this bit is ignored. bit 1 tcs: timer1 clock source select bit 1 = external clock from t1ck pin (on the rising edge) 0 = internal clock (f osc /2) bit 0 unimplemented: read as ? 0 ?
? 2009 microchip technology inc. preliminary ds39937b-page 103 pic24f04ka201 family 12.0 timer2/3 the timer2/3 module is a 32-bit timer, which can also be configured as two independent 16-bit timers with selectable operating modes. as a 32-bit timer, timer2/3 operates in three modes: ? two independent 16-bit timers (timer2 and timer3) with all 16-bit operating modes (except asynchronous counter mode) ? single 32-bit timer ? single 32-bit synchronous counter they also support these features: ? timer gate operation ? selectable prescaler settings ? timer operation during idle and sleep modes ? interrupt on a 32-bit period register match ? adc event trigger individually, both of the 16-bit timers can function as synchronous timers or counters. they also offer the features listed above, except for the adc event trigger (this is implemented only with timer3). the operating modes and enabled features are determined by setting the appropriate bit(s) in the t2con and t3con registers. t2con and t3con are provided in generic form in register 12-1 and register 12-2, respectively. for 32-bit timer/counter operation, timer2 is the least significant word (lsw) and timer3 is the most significant word (msw) of the 32-bit timer. to configure timer2/3 for 32-bit operation: 1. set the t32 bit (t2con<3> = 1 ). 2. select the prescaler ratio for timer2 using the tckps<1:0> bits. 3. set the clock and gating modes using the tcs and tgate bits. 4. load the timer period value. pr3 will contain the msw of the value while pr2 contains the lsw. 5. if interrupts are required, set the interrupt enable bit, t3ie; use the priority bits, t3ip<2:0>, to set the interrupt priority. while timer2 controls the timer, the interrupt appears as a timer3 interrupt. 6. set the ton bit (= 1 ). the timer value, at any point, is stored in the register pair, tmr<3:2>. tmr3 always contains the msw of the count, while tmr2 contains the lsw. to configure any of the timers for individual 16-bit operation: 1. clear the t32 bit in t2con<3>. 2. select the timer prescaler ratio using the tckps<1:0> bits. 3. set the clock and gating modes using the tcs and tgate bits. 4. load the timer period value into the prx register. 5. if interrupts are required, set the interrupt enable bit, txie; use the priority bits, txip<2:0>, to set the interrupt priority. 6. set the ton bit (txcon<15> = 1 ). note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on timers, refer to the ?pic24f family reference manual? , section 14. ?timers? (ds39704). note: for 32-bit operation, t3con control bits are ignored. only t2con control bits are used for setup and control. timer2 clock and gate inputs are utilized for the 32-bit timer modules, but an interrupt is generated with the timer3 interrupt flags.
pic24f04ka201 family ds39937b-page 104 preliminary ? 2009 microchip technology inc. figure 12-1: timer2/3 (32-bit) block diagram tmr3 tmr2 set t3if equal comparator pr3 pr2 reset lsb msb note 1: the 32-bit timer configuration (t32) bit must be set for 32-bit timer/counter operation. all control bits are respective to the t2con register. data bus<15:0> tmr3hld read tmr2 (1) write tmr2 (1) 16 16 16 q qd ck tgate 0 1 ton tckps<1:0> prescaler 1, 8, 64, 256 2 t cy tcs tgate gate t2ck sync adc event trigger sync 1x 01 00 16
? 2009 microchip technology inc. preliminary ds39937b-page 105 pic24f04ka201 family figure 12-2: timer2 (16-bi t synchronous) block diagram figure 12-3: timer3 (16-bi t synchronous) block diagram ton tckps<1:0> prescaler 1, 8, 64, 256 2 t cy tcs 1x 01 tgate 00 gate t2ck sync pr2 set t2if equal comparator tmr2 reset q qd ck tgate 1 0 sync ton tckps<1:0> 2 t cy tcs 1x 01 tgate 00 t3ck pr3 set t3if equal comparator tmr3 reset q qd ck tgate 1 0 adc event trigger prescaler 1, 8, 64, 256 sync
pic24f04ka201 family ds39937b-page 106 preliminary ? 2009 microchip technology inc. register 12-1: t2con: ti mer2 control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ton ?tsidl ? ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 u-0 ? tgate tckps1 tckps0 t32 (1) ?tcs ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ton: timer2 on bit when t2con<3> = 1 : 1 = starts 32-bit timer2/3 0 = stops 32-bit timer2/3 when t2con<3> = 0 : 1 = starts 16-bit timer2 0 = stops 16-bit timer2 bit 14 unimplemented: read as ? 0 ? bit 13 tsidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-7 unimplemented: read as ? 0 ? bit 6 tgate: timer2 gated time accumulation enable bit when tcs = 1 : this bit is ignored. when tcs = 0 : 1 = gated time accumulation enabled 0 = gated time accumulation disabled bit 5-4 tckps<1:0>: timer2 input clock prescale select bits 11 = 1:256 10 = 1:64 01 = 1:8 00 = 1:1 bit 3 t32: 32-bit timer mode select bit (1) 1 = timer2 and timer3 form a single 32-bit timer 0 = timer2 and timer3 act as two 16-bit timers bit 2 unimplemented: read as ? 0 ? bit 1 tcs: timer2 clock source select bit 1 = external clock from pin, t2ck (on the rising edge) 0 = internal clock (f osc /2) bit 0 unimplemented: read as ? 0 ? note 1: in 32-bit mode, the t3con control bits do not affect 32-bit timer operation.
? 2009 microchip technology inc. preliminary ds39937b-page 107 pic24f04ka201 family register 12-2: t3con: ti mer3 control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ton (1) ?tsidl (1) ? ? ? ? ? bit 15 bit 8 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 r/w-0 u-0 ?tgate (1) tckps1 (1) tckps0 (1) ? ?tcs (1) ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ton: timer3 on bit (1) 1 = starts 16-bit timer3 0 = stops 16-bit timer3 bit 14 unimplemented: read as ? 0 ? bit 13 tsidl: stop in idle mode bit (1) 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-7 unimplemented: read as ? 0 ? bit 6 tgate: timer3 gated time accumulation enable bit (1) when tcs = 1 : this bit is ignored. when tcs = 0 : 1 = gated time accumulation enabled 0 = gated time accumulation disabled bit 5-4 tckps<1:0>: timer3 input clock prescale select bits (1) 11 = 1:256 10 = 1:64 01 = 1:8 00 = 1:1 bit 3-2 unimplemented: read as ? 0 ? bit 1 tcs: timer3 clock source select bit (1) 1 = external clock from the t3ck pin (on the rising edge) 0 = internal clock (f osc /2) bit 0 unimplemented: read as ? 0 ? note 1: when 32-bit operation is enabled (t2con<3> = 1 ), these bits have no effect on timer3 operation; all timer functions are set through t2con.
pic24f04ka201 family ds39937b-page 108 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 109 pic24f04ka201 family 13.0 input capture the input capture module is used to capture a timer value from one of two selectable time bases upon an event on an input pin. the input capture features are quite useful in applications requiring frequency (time period) and pulse measurement. figure 13-1 depicts a simplified block diagram of the input capture module. the pic24f04ka201 family devices have one input capture channel. the input capture module has multiple operating modes, which are selected via the ic1con register. the operating modes include: ? capture timer value on every falling edge of input applied at the ic1 pin ? capture timer value on every rising edge of input applied at the ic1 pin ? capture timer value on every 4 th rising edge of input applied at the ic1 pin ? capture timer value on every 16 th rising edge of input applied at the ic1 pin ? capture timer value on every rising and every falling edge of input applied at the ic1 pin ? device wake-up from capture pin during cpu sleep and idle modes the input capture module has a four-level fifo buffer. the number of capture events required to generate a cpu interrupt can be selected by the user. figure 13-1: input capture block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on input capture, refer to the ?pic24f family reference manual? , section 15. ?input capture? (ds39701). ic1buf ic1 pin icm<2:0> (ic1con<2:0>) mode select 3 10 set flag ic1if (in ifsn register) tmry tmrx edge detection logic 16 16 fifo r/w logic ici<1:0> icov, icbne (ic1con<4:3>) ic1con interrupt logic system bus from 16-bit timers ictmr (ic1con<7>) prescaler counter (1, 4, 16) clock synchronizer
pic24f04ka201 family ds39937b-page 110 preliminary ? 2009 microchip technology inc. 13.1 input capture registers register 13-1: ic1con: input capture 1 control register u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ? ?icsidl ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r-0, hc r-0, hc r/w-0 r/w-0 r/w-0 ictmr ici1 ici0 icov icbne icm2 icm1 icm0 bit 7 bit 0 legend: hc = hardware clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 icsidl: input capture 1 module stop in idle control bit 1 = input capture module will halt in cpu idle mode 0 = input capture module will continue to operate in cpu idle mode bit 12-8 unimplemented: read as ? 0 ? bit 7 ictmr: input capture 1 timer select bit 1 = tmr2 contents are captured on capture event 0 = tmr3 contents are captured on capture event bit 6-5 ici<1:0>: select number of captures per interrupt bits 11 = interrupt on every fourth capture event 10 = interrupt on every third capture event 01 = interrupt on every second capture event 00 = interrupt on every capture event bit 4 icov: input capture 1 overflow status flag bit (read-only) 1 = input capture overflow occurred 0 = no input capture overflow occurred bit 3 icbne: input capture 1 buffer empty status bit (read-only) 1 = input capture buffer is not empty, at least one more capture value can be read 0 = input capture buffer is empty bit 2-0 icm<2:0>: input capture 1 mode select bits 111 = input capture functions as interrupt pin only when device is in sleep or idle mode (rising edge detect only, all other control bits are not applicable) 110 = unused (module disabled) 101 = capture mode, every 16th rising edge 100 = capture mode, every 4th rising edge 011 = capture mode, every rising edge 010 = capture mode, every falling edge 001 = capture mode, every edge (rising and falling) ? ici<1:0> bits do not control interrupt generation for this mode 000 = input capture module turned off
? 2009 microchip technology inc. preliminary ds39937b-page 111 pic24f04ka201 family 14.0 output compare 14.1 setup for single output pulse generation when the ocm control bits (oc1con<2:0>) are set to ? 100 ?, the selected output compare channel initializes the oc1 pin to the low state and generates a single output pulse. to generate a single output pulse, the following steps are required (these steps assume the timer source is initially turned off, but this is not a requirement for the module operation): 1. determine the instruction clock cycle time. take into account the frequency of the external clock to the timer source (if one is used) and the timer prescaler settings. 2. calculate time to the rising edge of the output pulse relative to the tmry start value (0000h). 3. calculate the time to the falling edge of the pulse based on the desired pulse width and the time to the rising edge of the pulse. 4. write the values computed in steps 2 and 3 above into the output compare 1 register, oc1r, and the output compare 1 secondary register, oc1rs, respectively. 5. set timer period register, pry, to value equal to or greater than the value in oc1rs, the output compare 1 secondary register. 6. set the ocm bits to ? 100 ? and the octsel (oc1con<3>) bit to the desired timer source. the oc1 pin state will now be driven low. 7. set the ton (tycon<15>) bit to ? 1 ?, which enables the compare time base to count. 8. upon the first match between tmry and oc1r, the oc1 pin will be driven high. 9. when the incrementing timer, tmry, matches the output compare 1 secondary register, oc1rs, the second and trailing edge (high-to-low) of the pulse is driven onto the oc1 pin. no additional pulses are driven onto the oc1 pin and it remains low. as a result of the second compare match event, the oc1if inter- rupt flag bit is set, which will result in an interrupt if it is enabled, by setting the oc1ie bit. for further information on peripheral interrupts, refer to section 7.0 ?interrupt controller? . 10. to initiate another single pulse output, change the timer and compare register settings, if needed, and then issue a write to set the ocm bits to ? 100 ?. disabling and re-enabling of the timer and clearing the tmry register are not required, but may be advantageous for defining a pulse from a known event time boundary. the output compare module does not have to be disabled after the falling edge of the output pulse. another pulse can be initiated by rewriting the value of the oc1con register. 14.2 setup for continuous output pulse generation when the ocm control bits (oc1con<2:0>) are set to ? 101 ?, the selected output compare channel initializes the oc1 pin to the low state and generates output pulses on each and every compare match event. for the user to configure the module for the generation of a continuous stream of output pulses, the following steps are required (these steps assume the timer source is initially turned off, but this is not a requirement for the module operation): 1. determine the instruction clock cycle time. take into account the frequency of the external clock to the timer source (if one is used) and the timer prescaler settings. 2. calculate time to the rising edge of the output pulse relative to the tmry start value (0000h). 3. calculate the time to the falling edge of the pulse based on the desired pulse width and the time to the rising edge of the pulse. 4. write the values computed in step 2 and 3 above into the output compare 1 register, oc1r, and the output compare 1 secondary register, oc1rs, respectively. 5. set the timer period register, pry, to a value equal to or greater than the value in oc1rs. 6. set the ocm bits to ? 101 ? and the octsel bit to the desired timer source. the oc1 pin state will now be driven low. 7. enable the compare time base by setting the ton (tycon<15>) bit to ? 1 ?. 8. upon the first match between tmry and oc1r, the oc1 pin will be driven high. 9. when the compare time base, tmry, matches the oc1rs, the second and trailing edge (high-to-low) of the pulse is driven onto the oc1 pin. 10. as a result of the second compare match event, the oc1if interrupt flag bit is set. 11. when the compare time base and the value in its respective timer period register match, the tmry register resets to 0x0000 and resumes counting. 12. steps 8 through 11 are repeated and a con- tinuous stream of pulses is generated indefinitely. the oc1if flag is set on each oc1rs/tmry compare match event. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on output compare, refer to the ?pic24f family reference manual? , section 16. ?output compare? (ds39706).
pic24f04ka201 family ds39937b-page 112 preliminary ? 2009 microchip technology inc. 14.3 pulse-width modulation (pwm) mode the following steps should be taken when configuring the output compare module for pwm operation: 1. set the pwm period by writing to the selected timer period register (pry). 2. set the pwm duty cycle by writing to the oc1rs register. 3. write the oc1r register with the initial duty cycle. 4. enable interrupts, if required, for the timer and output compare modules. the output compare interrupt is required for pwm fault pin utilization. 5. configure the output compare module for one of two pwm operation modes by writing to the output compare mode bits, ocm<2:0> (oc1con<2:0>). 6. set the tmry prescale value and enable the time base by setting ton (txcon<15>) = 1 . 14.3.1 pwm period the pwm period is specified by writing to pry, the timer period register. the pwm period can be calculated using equation 14-1. equation 14-1: calculating the pwm period (1) 14.3.2 pwm duty cycle the pwm duty cycle is specified by writing to the oc1rs register. the oc1rs register can be written to at any time, but the duty cycle value is not latched into oc1r until a match between pry and tmry occurs (i.e., the period is complete). this provides a double buffer for the pwm duty cycle and is essential for glitchless pwm operation. in pwm mode, oc1r is a read-only register. some important boundary parameters of the pwm duty cycle include: ? if the output compare 1 register, oc1r, is loaded with 0000h, the oc1 pin will remain low (0% duty cycle). ? if oc1r is greater than pry (timer period register), the pin will remain high (100% duty cycle). ? if oc1r is equal to pry, the oc1 pin will be low for one time base count value and high for all other count values. see example 14-1 for pwm mode timing details. table 14-1 provides an example of pwm frequencies and resolutions for a device operating at 10 mips. equation 14-2: calculation for maximum pwm resolution (1) note: the oc1r register should be initialized before the output compare module is first enabled. the oc1r register becomes a read-only duty cycle register when the module is operated in the pwm modes. the value held in oc1r will become the pwm duty cycle for the first pwm period. the contents of the output compare 1 secondary register, oc1rs, will not be transferred into oc1r until a time base period match occurs. note: a pry value of n will produce a pwm period of n + 1 time base count cycles. for example, a value of 7 written into the pry register will yield a period consisting of 8 time base cycles. pwm period = [(pry) + 1] ? t cy ? (timer prescale value) pwm frequency = 1/[pwm period] where: note 1: based on t cy = 2 * t osc , doze mode and pll are disabled. ( ) maximum pwm resolution (bits) = f cy f pwm ? (timer prescale value) log 10 log 10 (2) bits note 1: based on f cy = f osc /2, doze mode and pll are disabled.
? 2009 microchip technology inc. preliminary ds39937b-page 113 pic24f04ka201 family example 14-1: pwm period and duty cycle calculations (1) table 14-1: example pwm frequencies and resolutions at 4 mips (f cy = 4 mhz) (1) table 14-2: example pwm frequencies and resolutions at 16 mips (f cy = 16 mhz) (1) pwm frequency 7.6 hz 61 hz 122 hz 977 hz 3.9 khz 31.3 khz 125 khz timer prescaler ratio 8111111 period register value ffffh ffffh 7fffh 0fffh 03ffh 007fh 001fh resolution (bits) 16 16 15 12 10 7 5 note 1: based on f cy = f osc /2, doze mode and pll are disabled. pwm frequency 30.5 hz 244 hz 488 hz 3.9 khz 15.6 khz 125 khz 500 khz timer prescaler ratio 8111111 period register value ffffh ffffh 7fffh 0fffh 03ffh 007fh 001fh resolution (bits) 16 16 15 12 10 7 5 note 1: based on f cy = f osc /2, doze mode and pll are disabled. 1. find the timer period register value for a desired pwm frequency of 52.08 khz, where f osc = 8 mhz with pll (32 mhz device clock rate) and a timer2 prescaler setting of 1:1. t cy = 2 * t osc = 62.5 ns pwm period = 1/pwm frequency = 1/52.08 khz = 19.2 s pwm period = (pr2 + 1) ? t cy ? (timer 2 prescale value) 19.2 s = (pr2 + 1) ? 62.5 ns ? 1 pr2 = 306 2. find the maximum resolution of the duty cycle that can be used with a 52.08 khz frequency and a 32 mhz device clock rate: pwm resolution = log 10 (f cy /f pwm )/log 10 2) bits = (log 10 (16 mhz/52.08 khz)/log 10 2) bits = 8.3 bits note 1: based on t cy = 2 * t osc , doze mode and pll are disabled.
pic24f04ka201 family ds39937b-page 114 preliminary ? 2009 microchip technology inc. figure 14-1: output comp are module block diagram comparator output logic q s r ocm<2:0> output enable oc1 (1) set flag bit oc1if (1) oc1rs (1) mode select 3 note 1: where ?x? is depicted, reference is made to the registers associated with the respective output compare channel 1. 2: ocfa pin controls oc1 channel. 3: each output compare channel can use one of two selectabl e time bases. refer to the device data sheet for the time bases associated with the module. octsel 0 1 16 16 ocfa (2) tmr register inputs from time bases (3) period match signals from time bases (3) 0 1 oc1r (1)
? 2009 microchip technology inc. preliminary ds39937b-page 115 pic24f04ka201 family 14.4 output compare register register 14-1: oc1con: output compare 1 control register u-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 ? ?ocsidl ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r-0, hc r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? ocflt octsel ocm2 ocm1 ocm0 bit 7 bit 0 legend: hc = hardware clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-14 unimplemented: read as ? 0 ? bit 13 ocsidl: stop output compare 1 in idle mode control bit 1 = output compare 1 will halt in cpu idle mode 0 = output compare 1 will continue to operate in cpu idle mode bit 12-5 unimplemented: read as ? 0 ? bit 4 ocflt: pwm fault condition status bit 1 = pwm fault condition has occurred (cleared in hw only) 0 = no pwm fault condition has occurred (this bit is only used when ocm<2:0> = 111 ) bit 3 octsel: output compare 1 timer select bit 1 = timer3 is the clock source for output compare 1 0 = timer2 is the clock source for output compare 1 refer to the device data sheet for specific time bases available to the output compare module. bit 2-0 ocm<2:0>: output compare 1 mode select bits 111 = pwm mode on oc1, fault pin; ofca enabled (1) 110 = pwm mode on oc1, fault pin; ofca disabled (1) 101 = initialize oc1 pin low, generate continuous output pulses on oc1 pin 100 = initialize oc1 pin low, generate single output pulse on oc1 pin 011 = compare event toggles oc1 pin 010 = initialize oc1 pin high, compare event forces oc1 pin low 001 = initialize oc1 pin low, compare event forces oc1 pin high 000 = output compare channel is disabled note 1: ocfa pin controls oc1 channel.
pic24f04ka201 family ds39937b-page 116 preliminary ? 2009 microchip technology inc. register 14-2: padcfg1: pad co nfiguration control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 u-0 u-0 r/w-0 ? ? ? smbusdel (2) oc1tris (1) ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-5 unimplemented: read as ? 0 ? bit 3 oc1tris: oc1 output tri-state select bit (1) 1 = oc1 output will not be active on the pin; ocpwm1 can still be used for internal triggers 0 = oc1 output will be active on the pin based on the ocpwm1 module settings bit 2-0 unimplemented: read as ? 0 ? note 1: to enable the actual oc1 output, the ocpwm1 module has to be enabled. 2: bit 4 is described in section 16.0 ?inter-integrated circuit (i 2 c?)? .
? 2009 microchip technology inc. preliminary ds39937b-page 117 pic24f04ka201 family 15.0 serial peripheral interface (spi) the serial peripheral interface (spi) module is a synchronous serial interface useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be serial data eeproms, shift registers, display drivers, a/d converters, etc. the spi module is compatible with motorola?s spi and siop interfaces. the module supports operation in two buffer modes. in standard mode, data is shifted through a single serial buffer. in enhanced buffer mode, data is shifted through an 8-level fifo buffer. the module also supports a basic framed spi protocol while operating in either master or slave mode. a total of four framed spi configurations are supported. the spi serial interface consists of four pins: ? sdi1: serial data input ? sdo1: serial data output ? sck1: shift clock input or output ? ss1 : active-low slave select or frame synchronization i/o pulse the spi module can be configured to operate using 2, 3 or 4 pins. in the 3-pin mode, ss1 is not used. in the 2-pin mode, both sdo1 and ss1 are not used. block diagrams of the module in standard and enhanced buffer modes are displayed in figure 15-1 and figure 15-2. the devices of the pic24f04ka201 family offer one spi module on a device. to set up the spi module for the standard master mode of operation: 1. if using interrupts: a) clear the respective spi1if bit in the ifs0 register. b) set the respective spi1ie bit in the iec0 register. c) write the respective spi1ipx bits in the ipc2 register to set the interrupt priority. 2. write the desired settings to the spi1con1 and spi1con2 registers with the msten bit (spi1con1<5>) = 1 . 3. clear the spirov bit (spi1stat<6>). 4. enable spi operation by setting the spien bit (spi1stat<15>). 5. write the data to be transmitted to the spi1buf register. transmission (and reception) will start as soon as data is written to the spi1buf register. to set up the spi module for the standard slave mode of operation: 1. clear the spi1buf register. 2. if using interrupts: a) clear the respective spi1if bit in the ifs0 register. b) set the respective spi1ie bit in the iec0 register. c) write the respective spi1ip bits in the ipc2 register to set the interrupt priority. 3. write the desired settings to the spi1con1 and spi1con2 registers with the msten bit (spi1con1<5>) = 0 . 4. clear the smp bit. 5. if the cke bit is set, then the ssen bit (spi1con1<7>) must be set to enable the ss1 pin. 6. clear the spirov bit (spi1stat<6>). 7. enable spi operation by setting the spien bit (spi1stat<15>). note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the serial peripheral interface, refer to the ?pic24f family reference manual? , section 23. ?serial peripheral interface (spi)? (ds39699). note: do not perform read-modify-write operations (such as bit-oriented instructions) on the spi1buf register in either standard or enhanced buffer mode. note: in this section, the spi module is referred to as spi1, or separately as spi1. special function registers (sfrs) will follow a similar notation. for example, spi1con1 or spi1con2 refers to the control register for the spi1 module.
pic24f04ka201 family ds39937b-page 118 preliminary ? 2009 microchip technology inc. figure 15-1: spi1 mo dule block diagram (standard buffer mode) internal data bus sdi1 sdo1 ss1 /fsync1 sck1 spi1sr bit 0 shift control edge select f cy primary 1:1/4/16/64 enable prescaler sync spi1buf control transfer transfer write spi1buf read spi1buf 16 spi1con1<1:0> spi1con1<4:2> master clock secondary prescaler 1:1 to 1:8 clock control
? 2009 microchip technology inc. preliminary ds39937b-page 119 pic24f04ka201 family to set up the spi module for the enhanced buffer master (ebm) mode of operation: 1. if using interrupts: a) clear the respective spi1if bit in the ifs0 register. b) set the respective spi1ie bit in the iec0 register. c) write the respective spi1ipx bits in the ipc2 register. 2. write the desired settings to the spi1con1 and spi1con2 registers with the msten bit (spi1con1<5>) = 1 . 3. clear the spirov bit (spi1stat<6>). 4. select enhanced buffer mode by setting the spiben bit (spi1con2<0>). 5. enable spi operation by setting the spien bit (spi1stat<15>). 6. write the data to be transmitted to the spi1buf register. transmission (and reception) will start as soon as data is written to the spi1buf register. to set up the spi module for the enhanced buffer slave mode of operation: 1. clear the spi1buf register. 2. if using interrupts: a) clear the respective spi1if bit in the ifs0 register. b) set the respective spi1ie bit in the iec0 register. c) write the respective spi1ipx bits in the ipc2 register to set the interrupt priority. 3. write the desired settings to the spi1con1 and spi1con2 registers with the msten bit (spi1con1<5>) = 0 . 4. clear the smp bit. 5. if the cke bit is set, then the ssen bit must be set, thus enabling the ss1 pin. 6. clear the spirov bit (spi1stat<6>). 7. select enhanced buffer mode by setting the spiben bit (spi1con2<0>). 8. enable spi operation by setting the spien bit (spi1stat<15>). figure 15-2: spi1 mo dule block diagram (e nhanced buffer mode) internal data bus sdi1 sdo1 ss1 /fsync1 sck1 spi1sr bit 0 shift control edge select f cy enable sync spi1buf control transfer transfer write spi1buf read spi1buf 16 spi1con1<1:0> spi1con1<4:2> master clock 8-level fifo transmit buffer 8-level fifo receive buffer clock control primary 1:1/4/16/64 prescaler secondary prescaler 1:1 to 1:8
pic24f04ka201 family ds39937b-page 120 preliminary ? 2009 microchip technology inc. register 15-1: spi1stat: spi1 status and control register r/w-0 u-0 r/w-0 u-0 u-0 r-0, hsc r-0, hsc r-0, hsc spien ? spisidl ? ? spibec2 spibec1 spibec0 bit 15 bit 8 r-0,hsc r/c-0, hs r/w-0, hsc r/w-0 r/w-0 r/w-0 r-0, hsc r-0, hsc srmpt spirov srxmpt sisel2 sisel1 sisel0 spitbf spirbf bit 7 bit 0 legend: hs = hardware settable bit hsc = hardware settable/clearable bit c = clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 spien: spi1 enable bit 1 = enables module and configures sck1, sdo1, sdi1 and ss1 as serial port pins 0 = disables module bit 14 unimplemented: read as ? 0 ? bit 13 spisidl: stop in idle mode bit 1 = discontinues module operation when device enters idle mode 0 = continues module operation in idle mode bit 12-11 unimplemented: read as ? 0 ? bit 10-8 spibec<2:0>: spi1 buffer element count bits (valid in enhanced buffer mode) master mode: number of spi transfers pending. slave mode: number of spi transfers unread. bit 7 srmpt: shift register (spi1sr) empty bit (valid in enhanced buffer mode) 1 = spi1 shift register is empty and ready to send or receive 0 = spi1 shift register is not empty bit 6 spirov: receive overflow flag bit 1 = a new byte/word is completely received and discarded. the user software has not read the previous data in the spi1buf register. 0 = no overflow has occurred bit 5 srxmpt: receive fifo empty bit (valid in enhanced buffer mode) 1 = receive fifo is empty 0 = receive fifo is not empty bit 4-2 sisel<2:0>: spi1 buffer interrupt mode bits (valid in enhanced buffer mode) 111 = interrupt when spi1 transmit buffer is full (spitbf bit is set) 110 = interrupt when last bit is shifted into spi1sr; as a result, the tx fifo is empty 101 = interrupt when the last bit is shifted out of spi1sr; now the transmit is complete 100 = interrupt when one data byte is shifted into the spi1sr; as a result, the tx fifo has one open spot 011 = interrupt when spi1 receive buffer is full (spirbf bit set) 010 = interrupt when spi1 receive buffer is 3/4 or more full 001 = interrupt when data is available in receive buffer (srmpt bit is set) 000 = interrupt when the last data in the receive buffer is read; as a result, the buffer is empty (srxmpt bit is set)
? 2009 microchip technology inc. preliminary ds39937b-page 121 pic24f04ka201 family bit 1 spitbf: spi1 transmit buffer full status bit 1 = transmit not yet started, spi1txb is full 0 = transmit started, spi1txb is empty in standard buffer mode: automatically set in hardware when cpu writes spi1buf location, loading spi1txb. automatically cleared in hardware when spi1 module transfers data from spi1txb to spi1sr. in enhanced buffer mode: automatically set in hardware when cpu writes spi1buf location, loading the last available buffer location. automatically cleared in hardware when a buffer location is available for a cpu write. bit 0 spirbf: spi1 receive buffer full status bit 1 = receive complete, spi1rxb is full 0 = receive is not complete, spi1rxb is empty in standard buffer mode: automatically set in hardware when spi1 transfers data from spi1sr to spi1rxb. automatically cleared in hardware when core reads spi1buf location, reading spi1rxb. in enhanced buffer mode: automatically set in hardware when spi1 transfers data from spi1sr to buffer, filling the last unread buffer location. automatically cleared in hardware when a buffer location is available for a transfer from spi1sr. register 15-1: spi1stat: spi1 status and control register (continued)
pic24f04ka201 family ds39937b-page 122 preliminary ? 2009 microchip technology inc. register 15-2: spi1con1: spi1 control register 1 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? dissck dissdo mode16 smp cke (1) bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ssen ckp msten spre2 spre1 spre0 ppre1 ppre0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-13 unimplemented: read as ? 0 ? bit 12 dissck: disable sck1 pin bit (spi master modes only) 1 = internal spi clock is disabled, pin functions as i/o 0 = internal spi clock is enabled bit 11 dissdo: disables sdo1 pin bit 1 = sdo1 pin is not used by module; pin functions as i/o 0 = sdo1 pin is controlled by the module bit 10 mode16: word/byte communication select bit 1 = communication is word-wide (16 bits) 0 = communication is byte-wide (8 bits) bit 9 smp: spi1 data input sample phase bit master mode: 1 = input data sampled at end of data output time 0 = input data sampled at middle of data output time slave mode: smp must be cleared when spi1 is used in slave mode. bit 8 cke: spi1 clock edge select bit (1) 1 = serial output data changes on transition from active clock state to idle clock state (see bit 6) 0 = serial output data changes on transition from idle clock state to active clock state (see bit 6) bit 7 ssen: slave select enable bit (slave mode) 1 =ss1 pin used for slave mode 0 =ss1 pin not used by module; pin controlled by port function bit 6 ckp: clock polarity select bit 1 = idle state for clock is a high level; active state is a low level 0 = idle state for clock is a low level; active state is a high level bit 5 msten: master mode enable bit 1 = master mode 0 =slave mode bit 4-2 spre<2:0>: secondary prescale bits (master mode) 111 = secondary prescale 1:1 110 = secondary prescale 2:1 . . . 000 = secondary prescale 8:1 note 1: the cke bit is not used in the framed spi modes. the user should program this bit to ? 0 ? for the framed spi modes (frmen = 1 ).
? 2009 microchip technology inc. preliminary ds39937b-page 123 pic24f04ka201 family bit 1-0 ppre<1:0>: primary prescale bits (master mode) 11 = primary prescale 1:1 10 = primary prescale 4:1 01 = primary prescale 16:1 00 = primary prescale 64:1 register 15-2: spi1con1: spi1 control register 1 (continued) note 1: the cke bit is not used in the framed spi modes. the user should program this bit to ? 0 ? for the framed spi modes (frmen = 1 ). register 15-3: spi1con2: spi1 control register 2 r/w-0 r/w-0 r/w-0 u-0 u-0 u-0 u-0 u-0 frmen spifsd spifpol ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 ? ? ? ? ? ? spife spiben bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 frmen: framed spi1 support bit 1 = framed spi1 support enabled 0 = framed spi1 support disabled bit 14 spifsd: frame sync pulse direction control on ss1 pin bit 1 = frame sync pulse input (slave) 0 = frame sync pulse output (master) bit 13 spifpol: frame sync pulse polarity bit (frame mode only) 1 = frame sync pulse is active-high 0 = frame sync pulse is active-low bit 12-2 unimplemented: read as ? 0 ? bit 1 spife: frame sync pulse edge select bit 1 = frame sync pulse coincides with first bit clock 0 = frame sync pulse precedes first bit clock bit 0 spiben: enhanced buffer enable bit 1 = enhanced buffer enabled 0 = enhanced buffer disabled (legacy mode)
pic24f04ka201 family ds39937b-page 124 preliminary ? 2009 microchip technology inc. equation 15-1: relationship between device and spi clock speed (1) table 15-1: sample sck frequencies (1,2) f cy = 16 mhz secondary prescaler settings 1:12:14:16:18:1 primary prescaler settings 1:1 invalid 8000 4000 2667 2000 4:1 4000 2000 1000 667 500 16:1 1000 500 250 167 125 64:1 250 125 63 42 31 f cy = 5 mhz primary prescaler settings 1:1 5000 2500 1250 833 625 4:1 1250 625 313 208 156 16:1 313 156 78 52 39 64:17839201310 note 1: based on f cy = f osc /2, doze mode and pll are disabled. 2: sck1 frequencies indicated in khz. primary prescaler * secondary prescaler f cy f sck = note 1: based on f cy = f osc /2, doze mode and pll are disabled.
? 2009 microchip technology inc. preliminary ds39937b-page 125 pic24f04ka201 family 16.0 inter-integrated circuit (i 2 c?) the inter-integrated circuit (i 2 c?) module is a serial interface useful for communicating with other peripheral or microcontroller devices. these peripheral devices may be serial data eeproms, display drivers, a/d converters, etc. the i 2 c module supports these features: ? independent master and slave logic ? 7-bit and 10-bit device addresses ? general call address, as defined in the i 2 c protocol ? clock stretching to provide delays for the processor to respond to a slave data request ? both 100 khz and 400 khz bus specifications ? configurable address masking ? multi-master modes to prevent loss of messages in arbitration ? bus repeater mode, allowing the acceptance of all messages as a slave regardless of the address ? automatic scl figure 16-1 illustrates a block diagram of the module. 16.1 pin remapping options the i 2 c module is tied to a fixed pin. to allow flexibility with peripheral multiplexing, the i2c1 module in 20-pin devices can be reassigned to the alternate pins, designated as scl1 and sda1 during device configuration. pin assignment is controlled by the i2c1sel configuration bit. programming this bit (= 0 ) multiplexes the module to the scl1 and sda1 pins. 16.2 communicating as a master in a single master environment the details of sending a message in master mode depends on the communications protocol for the device being communicated with. typically, the sequence of events is as follows: 1. assert a start condition on sda1 and scl1. 2. send the i 2 c device address byte to the slave with a write indication. 3. wait for and verify an acknowledge from the slave. 4. send the first data byte (sometimes known as the command) to the slave. 5. wait for and verify an acknowledge from the slave. 6. send the serial memory address low byte to the slave. 7. repeat steps 4 and 5 until all data bytes are sent. 8. assert a repeated start condition on sda1 and scl1. 9. send the device address byte to the slave with a read indication. 10. wait for and verify an acknowledge from the slave. 11. enable master reception to receive serial memory data. 12. generate an ack or nack condition at the end of a received byte of data. 13. generate a stop condition on sda1 and scl1. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the inter-integrated circuit, refer to the ?pic24f family reference manual? , section 24. ?inter-integrated circuit (i 2 c?)? (ds39702).
pic24f04ka201 family ds39937b-page 126 preliminary ? 2009 microchip technology inc. figure 16-1: i 2 c? block diagram i2c1rcv internal data bus scl1 sda1 shift match detect i2c1add start and stop bit detect clock address match clock stretching i2c1trn lsb shift clock brg down counter reload control t cy /2 start and stop bit generation acknowledge generation collision detect i2c1con i2c1stat control logic read lsb write read i2c1brg i2c1rsr write read write read write read write read write read i2c1msk
? 2009 microchip technology inc. preliminary ds39937b-page 127 pic24f04ka201 family 16.3 setting baud rate when operating as a bus master to compute the baud rate generator (brg) reload value, use equation 16-1. equation 16-1: computing baud rate reload value (1) 16.4 slave address masking the i2c1msk register (register 16-3) designates address bit positions as ?don?t care? for both 7-bit and 10-bit addressing modes. setting a particular bit location (= 1 ) in the i2c1msk register causes the slave module to respond whether the corresponding address bit value is ? 0 ? or ? 1 ?. for example, when i2c1msk is set to ? 00100000 ?, the slave module will detect both addresses: ? 0000000 ? and ? 00100000 ?. to enable address masking, the intelligent peripheral management interface (ipmi) must be disabled by clearing the ipmien bit (i2c1con<11>). table 16-1: i 2 c? clock rates (1) table 16-2: i 2 c? reserved addresses (1) i2c1brg f cy f scl ----------- - f cy 10 000 000 ,, ----------------------------- - ? ?? ?? 1 ? = f scl f cy i2c1brg 1 f cy 10 000 000 ,, ----------------------------- - ++ --------------------------------------------------------------------- - = or note 1: based on f cy = f osc /2, doze mode and pll are disabled. note: as a result of changes in the i 2 c protocol, the addresses in table 16-2 are reserved and will not be acknowledged in slave mode. this includes any address mask settings that include any of these addresses. required system f scl f cy i2c1brg value actual f scl (decimal) (hexadecimal) 100 khz 16 mhz 157 9d 100 khz 100 khz 8 mhz 78 4e 100 khz 100 khz 4 mhz 39 27 99 khz 400 khz 16 mhz 37 25 404 khz 400 khz 8 mhz 18 12 404 khz 400khz 4mhz 9 9 385khz 400khz 2mhz 4 4 385khz 1 mhz 16 mhz 13 d 1.026 mhz 1mhz 8mhz 6 6 1.026mhz 1mhz 4mhz 3 3 0.909mhz note 1: based on f cy = f osc /2, doze mode and pll are disabled. slave address r/w bit description 0000 000 0 general call address (2) 0000 000 1 start byte 0000 001 x cbus address 0000 010 x reserved 0000 011 x reserved 0000 1xx x hs mode master code 1111 1xx x reserved 1111 0xx x 10-bit slave upper byte (3) note 1: the address bits listed here will never cause an address match, independent of the address mask settings. 2: address will be acknowledged only if gcen = 1 . 3: match on this address can only occur on the upper byte in 10-bit addressing mode.
pic24f04ka201 family ds39937b-page 128 preliminary ? 2009 microchip technology inc. register 16-1: i2c1con: i2c1 control register r/w-0 u-0 r/w-0 r/w-1 hc r/w-0 r/w-0 r/w-0 r/w-0 i2cen ? i2csidl sclrel ipmien a10m disslw smen bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0, hc r/w-0, hc r/w-0, hc r/w-0, hc r/w-0, hc gcen stren ackdt acken rcen pen rsen sen bit 7 bit 0 legend: hc = hardware clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 i2cen: i2c1 enable bit 1 = enables the i2c1 module and configures the sda1 and scl1 pins as serial port pins 0 = disables the i2c1 module; all i 2 c? pins are controlled by port functions bit 14 unimplemented: read as ? 0 ? bit 13 i2csidl: stop in idle mode bit 1 = discontinues module operation when device enters an idle mode 0 = continues module operation in idle mode bit 12 sclrel: scl1 release control bit (when operating as i 2 c slave) 1 = releases scl1 clock 0 = holds scl1 clock low (clock stretch) if stren = 1 : bit is r/w (i.e., software may write ? 0 ? to initiate stretch and write ? 1 ? to release clock). hardware clear at beginning of slave transmission. hardware clear at end of slave reception. if stren = 0 : bit is r/s (i.e., software may only write ? 1 ? to release clock). hardware clear at beginning of slave transmission. bit 11 ipmien: intelligent peripheral management interface (ipmi) enable bit 1 = ipmi support mode is enabled; all addresses acknowledged 0 = ipmi support mode is disabled bit 10 a10m: 10-bit slave addressing bit 1 = i2c1add is a 10-bit slave address 0 = i2c1add is a 7-bit slave address bit 9 disslw: disable slew rate control bit 1 = slew rate control disabled 0 = slew rate control enabled bit 8 smen: smbus input levels bit 1 = enables i/o pin thresholds compliant with the smbus specification 0 = disables the smbus input thresholds bit 7 gcen: general call enable bit (when operating as i 2 c slave) 1 = enables interrupt when a general call address is received in the i2c1rsr (module is enabled for reception) 0 = general call address disabled bit 6 stren: scl1 clock stretch enable bit (when operating as i 2 c slave) used in conjunction with the sclrel bit. 1 = enables software or receive clock stretching 0 = disables software or receive clock stretching
? 2009 microchip technology inc. preliminary ds39937b-page 129 pic24f04ka201 family bit 5 ackdt: acknowledge data bit (when operating as i 2 c master; applicable during master receive) value that will be transmitted when the software initiates an acknowledge sequence. 1 = sends nack during acknowledge 0 = sends ack during acknowledge bit 4 acken: acknowledge sequence enable bit (when operating as i 2 c master; applicable during master receive) 1 = initiates acknowledge sequence on sda1 and scl1 pins and transmits ackdt data bit; hardware clear at end of master acknowledge sequence 0 = acknowledge sequence not in progress bit 3 rcen: receive enable bit (when operating as i 2 c master) 1 = enables receive mode for i 2 c; hardware clear at end of eighth bit of master receive data byte 0 = receive sequence not in progress bit 2 pen: stop condition enable bit (when operating as i 2 c master) 1 = initiates stop condition on sda1 and scl1 pins; hardware clear at end of master stop sequence 0 = stop condition not in progress bit 1 rsen: repeated start condition enable bit (when operating as i 2 c master) 1 = initiates repeated start condition on sda1 and scl1 pins; hardware clear at end of master repeated start sequence 0 = repeated start condition not in progress bit 0 sen: start condition enable bit (when operating as i 2 c master) 1 = initiates start condition on sda1 and scl1 pins; hardware clear at end of master start sequence 0 = start condition not in progress register 16-1: i2c1con: i2c1 control register (continued)
pic24f04ka201 family ds39937b-page 130 preliminary ? 2009 microchip technology inc. register 16-2: i2c1stat: i2c1 status register r-0, hsc r-0, hsc u-0 u-0 u-0 r/c-0, hs r-0, hsc r-0, hsc ackstat trstat ? ? ? bcl gcstat add10 bit 15 bit 8 r/c-0, hs r/c-0, hs r-0, hsc r/c-0, hsc r/c-0, hsc r-0, hsc r-0, hsc r-0, hsc iwcol i2cov d/a psr/w rbf tbf bit 7 bit 0 legend: c = clearable bit hs = hardware settable bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ackstat: acknowledge status bit 1 = nack was detected last 0 = ack was detected last hardware set or clear at end of acknowledge. bit 14 trstat: transmit status bit (when operating as i 2 c? master; applicable to master transmit operation.) 1 = master transmit is in progress (8 bits + ack) 0 = master transmit is not in progress hardware set at beginning of master transmission; hardware clear at end of slave acknowledge. bit 13-11 unimplemented: read as ? 0 ? bit 10 bcl: master bus collision detect bit 1 = a bus collision has been detected during a master operation 0 = no collision hardware set at detection of bus collision. bit 9 gcstat: general call status bit 1 = general call address was received 0 = general call address was not received hardware set when address matches general call address; hardware clear at stop detection. bit 8 add10: 10-bit address status bit 1 = 10-bit address was matched 0 = 10-bit address was not matched hardware set at match of 2 nd byte of matched 10-bit address; hardware clear at stop detection. bit 7 iwcol: write collision detect bit 1 = an attempt to write to the i2c1trn register failed because the i 2 c module is busy 0 = no collision hardware set at occurrence of write to i2c1trn while busy (cleared by software). bit 6 i2cov: receive overflow flag bit 1 = a byte was received while the i2c1rcv register is still holding the previous byte 0 = no overflow hardware set at attempt to transfer i2c1rsr to i2c1rcv (cleared by software). bit 5 d/a : data/address bit (when operating as i 2 c slave) 1 = indicates that the last byte received was data 0 = indicates that the last byte received was the device address hardware clear at device address match; hardware set by write to i2c1trn or by reception of slave byte. bit 4 p: stop bit 1 = indicates that a stop bit has been detected last 0 = stop bit was not detected last hardware set or clear when start, repeated start or stop detected.
? 2009 microchip technology inc. preliminary ds39937b-page 131 pic24f04ka201 family bit 3 s: start bit 1 = indicates that a start (or repeated start) bit has been detected last 0 = start bit was not detected last hardware set or clear when start, repeated start or stop detected. bit 2 r/w : read/write information bit (when operating as i 2 c slave) 1 = read ? indicates data transfer is output from slave 0 = write ? indicates data transfer is input to slave hardware set or clear after reception of i 2 c device address byte. bit 1 rbf: receive buffer full status bit 1 = receive complete, i2c1rcv is full 0 = receive not complete, i2c1rcv is empty hardware set when i2c1rcv is written with received byte; hardware clear when software reads i2c1rcv. bit 0 tbf: transmit buffer full status bit 1 = transmit in progress, i2c1trn is full 0 = transmit complete, i2c1trn is empty hardware set when software writes to i2c1trn; hardware clear at completion of data transmission. register 16-2: i2c1stat: i2c1 status register (continued)
pic24f04ka201 family ds39937b-page 132 preliminary ? 2009 microchip technology inc. register 16-3: i2c1msk: i2c1 sl ave mode address mask register u-0 u-0 u-0 u-0 u-0 u-0 r/w-0 r/w-0 ? ? ? ? ? ? amsk9 amsk8 bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 amsk7 amsk6 amsk5 amsk4 amsk3 amsk2 amsk1 amsk0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-10 unimplemented: read as ? 0 ? bit 9-0 amsk<9:0>: mask for address bit x select bits 1 = enable masking for bit x of incoming message address; bit match not required in this position 0 = disable masking for bit x; bit match required in this position register 16-4: padcfg1: pad co nfiguration control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 r/w-0 r/w-0 u-0 u-0 u-0 ? ? ? smbusdel oc1tris (1,2) ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-5 unimplemented: read as ? 0 ? bit 4 smbusdel: smbus sda input delay select bit 1 = the i 2 c? module is configured for a longer smbus input delay (nominal 300 ns delay) 0 = the 1 2 c module is configured for a legacy input delay (nominal 150 ns delay) bit 2-0 unimplemented: read as ? 0 ? note 1: to enable the actual oc1 output, the ocpwm1 module has to be enabled. 2: bit 3 is described in related chapters.
? 2009 microchip technology inc. preliminary ds39937b-page 133 pic24f04ka201 family 17.0 universal asynchronous receiver transmitter (uart) the universal asynchronous receiver transmitter (uart) module is one of the serial i/o modules avail- able in this pic24f device family. the uart is a full-duplex asynchronous system that can communicate with peripheral devices, such as personal computers, lin, rs-232 and rs-485 interfaces. this module also supports a hardware flow control option with the u1cts and u1rts pins, and also includes an irda ? encoder and decoder. the primary features of the uart module are: ? full-duplex, 8-bit or 9-bit data transmission through the u1tx and u1rx pins ? even, odd or no parity options (for 8-bit data) ? one or two stop bits ? hardware flow control option with u1cts and u1rts pins ? fully integrated baud rate generator (ibrg) with 16-bit prescaler ? baud rates ranging from 1 mbps to 15 bps at 16 mips ? 4-deep, first-in-first-out (fifo) transmit data buffer ? 4-deep fifo receive data buffer ? parity, framing and buffer overrun error detection ? support for 9-bit mode with address detect (9 th bit = 1 ) ? transmit and receive interrupts ? loopback mode for diagnostic support ? support for sync and break characters ? supports automatic baud rate detection ? irda encoder and decoder logic ? 16x baud clock output for irda support a simplified block diagram of the uart is displayed in figure 17-1. the uart module consists of these important hardware elements: ? baud rate generator ? asynchronous transmitter ? asynchronous receiver figure 17-1: uart simplified block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the universal asynchronous receiver transmitter, refer to the ?pic24f family reference manual? , section 21. ?uart? (ds39708). u1rx irda ? hardware flow control uart1 receiver uart1 transmitter u1tx u1cts u1rts u1bclk baud rate generator
pic24f04ka201 family ds39937b-page 134 preliminary ? 2009 microchip technology inc. 17.1 uart baud rate generator (brg) the uart module includes a dedicated 16-bit baud rate generator (brg). t he u1brg register controls the period of a free-running, 16-bit timer. equation 17-1 provides the formula for computation of the baud rate with brgh = 0 . equation 17-1: uart baud rate with brgh = 0 (1) example 17-1 provides the calculation of the baud rate error for the following conditions: ?f cy = 4 mhz ? desired baud rate = 9600 the maximum baud rate (brgh = 0 ) possible is f cy /16 (for u1brg = 0 ) and the minimum baud rate possible is f cy /(16 * 65536). equation 17-2 provides the formula for computation of the baud rate with brgh = 1 . equation 17-2: uart baud rate with brgh = 1 (1) the maximum baud rate (brgh = 1 ) possible is f cy /4 (for u1brg = 0 ) and the minimum baud rate possible is f cy /(4 * 65536). writing a new value to the u1brg register causes the brg timer to be reset (cleared). this ensures the brg does not wait for a timer overflow before generating the new baud rate. example 17-1: baud rate erro r calculation (brgh = 0 ) (1) note 1: based on f cy = f osc /2, doze mode and pll are disabled. baud rate = f cy 16 ? (u1brg + 1) f cy 16 ? baud rate u1brg = ? 1 baud rate = f cy 4 ? (u1brg + 1) f cy 4 ? baud rate u1brg = ? 1 note 1: based on f cy = f osc /2, doze mode and pll are disabled. desired baud rate = f cy /(16 (u1brg + 1)) solving for uxbrg value: u1brg = ((f cy /desired baud rate)/16) ? 1 u1brg = ((4000000/9600)/16) ? 1 u1brg = 25 calculated baud rate = 4000000/(16 (25 + 1)) = 9615 error = (calculated baud rate ? desired baud rate) desired baud rate = (9615 ? 9600)/9600 =0.16% note 1: based on f cy = f osc /2, doze mode and pll are disabled.
? 2009 microchip technology inc. preliminary ds39937b-page 135 pic24f04ka201 family 17.2 transmitting in 8-bit data mode 1. set up the uart: a) write appropriate values for data, parity and stop bits. b) write appropriate baud rate value to the u1brg register. c) set up transmit and receive interrupt enable and priority bits. 2. enable the uart. 3. set the utxen bit (causes a transmit interrupt two cycles after being set). 4. write data byte to lower byte of u1txreg word. the value will be immediately transferred to the transmit shift register (tsr), and the serial bit stream will start shifting out with the next rising edge of the baud clock. 5. alternately, the data byte may be transferred while utxen = 0 , and then, the user may set utxen. this will cause the serial bit stream to begin immediately because the baud clock will start from a cleared state. 6. a transmit interrupt will be generated as per interrupt control bit, utxisel1. 17.3 transmitting in 9-bit data mode 1. set up the uart (as described in section 17.2 ?transmitting in 8-bit data mode? ). 2. enable the uart. 3. set the utxen bit (causes a transmit interrupt two cycles after being set). 4. write u1txreg as a 16-bit value only. 5. a word write to u1txreg triggers the transfer of the 9-bit data to the tsr. the serial bit stream will start shifting out with the first rising edge of the baud clock. 6. a transmit interrupt will be generated as per the setting of control bit, utxisel1. 17.4 break and sync transmit sequence the following sequence will send a message frame header made up of a break, followed by an auto-baud sync byte. 1. configure the uart for the desired mode. 2. set utxen and utxbrk ? sets up the break character. 3. load the u1txreg with a dummy character to initiate transmission (value is ignored). 4. write ?55h? to u1txreg ? loads the sync character into the transmit fifo. 5. after the break has been sent, the utxbrk bit is reset by hardware. the sync character now transmits. 17.5 receiving in 8-bit or 9-bit data mode 1. set up the uart (as described in section 17.2 ?transmitting in 8-bit data mode? ). 2. enable the uart. 3. a receive interrupt will be generated when one or more data characters have been received as per interrupt control bit, urxisel1. 4. read the oerr bit to determine if an overrun error has occurred. the oerr bit must be reset in software. 5. read u1rxreg. the act of reading the uxrxreg character will move the next character to the top of the receive fifo, including a new set of perr and ferr values. 17.6 operation of u1cts and u1rts control pins uart1 clear to send (u1cts ) and request to send (u1rts ) are the two hardware-controlled pins that are associated with the uart module. these two pins allow the uart to operate in simplex and flow control modes. they are implemented to control the transmission and reception between the data terminal equipment (dte). the uen<1:0> bits in the u1mode register configure these pins. 17.7 infrared support the uart module provides two types of infrared uart support: one is the irda clock output to support an external irda encoder and decoder device (legacy module support), and the other is the full implementation of the irda encoder and decoder. as the irda modes require a 16x baud clock, they will only work when the brgh bit (u1mode<3>) is ? 0 ?. 17.7.1 external irda support ? irda clock output to support external irda encoder and decoder devices, the u1bclk pin (same as the u1rts pin) can be configured to generate the 16x baud clock. when uen<1:0> = 11 , the u1bclk pin will output the 16x baud clock if the uart module is enabled; it can be used to support the irda codec chip. 17.7.2 built-in irda encoder and decoder the uart has full implementation of the irda encoder and decoder as part of the uart module. the built-in irda encoder and decoder functionality is enabled using the iren bit (u1mode<12>). when enabled (iren = 1 ), the receive pin (u1rx) acts as the input from the infrared receiver. the transmit pin (u1tx) acts as the output to the infrared transmitter.
pic24f04ka201 family ds39937b-page 136 preliminary ? 2009 microchip technology inc. register 17-1: u1mode: uart1 mode register r/w-0 u-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 (2) r/w-0 (2) uarten ? usidl iren (1) rtsmd ? uen1 uen0 bit 15 bit 8 r/c-0, hc r/w-0 r/w-0, hc r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 wake lpback abaud rxinv brgh pdsel1 pdsel0 stsel bit 7 bit 0 legend: c = clearable bit hc = hardware clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 uarten: uart1 enable bit 1 = uart1 is enabled; all uart1 pins are controlled by uart1 as defined by uen<1:0> 0 = uart1 is disabled; all uart1 pins are controlled by port latches; uart1 power consumption is minimal bit 14 unimplemented: read as ? 0 ? bit 13 usidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12 iren: irda ? encoder and decoder enable bit (1) 1 = irda encoder and decoder enabled 0 = irda encoder and decoder disabled bit 11 rtsmd: mode selection for u1rts pin bit 1 =u1rts pin in simplex mode 0 =u1rts pin in flow control mode bit 10 unimplemented: read as ? 0 ? bit 9-8 uen<1:0>: uart1 enable bits (2) 11 = u1tx, u1rx and u1bclk pins are enabled and used; u1cts pin controlled by port latches 10 = u1tx, u1rx, u1cts and u1rts pins are enabled and used 01 = u1tx, u1rx and u1rts pins are enabled and used; u1cts pin controlled by port latches 00 = u1tx and uxrx pins are enabled and used; u1cts and u1rts /u1bclk pins controlled by port latches bit 7 wake: wake-up on start bit detect during sleep mode enable bit 1 = uart1 will continue to sample the u1rx pin; interrupt generated on falling edge, bit cleared in hardware on following rising edge 0 = no wake-up enabled bit 6 lpback: uart1 loopback mode select bit 1 = enable loopback mode 0 = loopback mode is disabled bit 5 abaud: auto-baud enable bit 1 = enable baud rate measurement on the next character ? requires reception of a sync field (55h); cleared in hardware upon completion 0 = baud rate measurement disabled or completed bit 4 rxinv: receive polarity inversion bit 1 = u1rx idle state is ? 0 ? 0 = u1rx idle state is ? 1 ? note 1: this feature is only available for the 16x brg mode (brgh = 0 ). 2: bit availability depends on pin availability.
? 2009 microchip technology inc. preliminary ds39937b-page 137 pic24f04ka201 family bit 3 brgh: high baud rate enable bit 1 = brg generates 4 clocks per bit period (4x baud clock, high-speed mode) 0 = brg generates 16 clocks per bit period (16x baud clock, standard mode) bit 2-1 pdsel<1:0>: parity and data selection bits 11 = 9-bit data, no parity 10 = 8-bit data, odd parity 01 = 8-bit data, even parity 00 = 8-bit data, no parity bit 0 stsel: stop bit selection bit 1 = two stop bits 0 = one stop bit register 17-1: u1mode: uart1 mode register (continued) note 1: this feature is only available for the 16x brg mode (brgh = 0 ). 2: bit availability depends on pin availability.
pic24f04ka201 family ds39937b-page 138 preliminary ? 2009 microchip technology inc. register 17-2: u1sta: uart1 status and control register r/w-0 r/w-0 r/w-0 u-0 r/w-0, hc r/w-0 r-0, hsc r-1, hsc utxisel1 utxinv utxisel0 ? utxbrk utxen utxbf trmt bit 15 bit 8 r/w-0 r/w-0 r/w-0 r-1, hsc r-0, hsc r-0, hsc r/c-0, hs r-0, hsc urxisel1 urxisel0 adden ridle perr ferr oerr urxda bit 7 bit 0 legend: c = clearable bit hc = hardware clearable bit hs = hardware settable bit hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15,13 utxisel<1:0>: transmission interrupt mode selection bits 11 = reserved; do not use 10 = interrupt when a character is transferred to the transmit shift register (tsr), and as a result, the transmit buffer becomes empty 01 = interrupt when the last character is shifted out of the transmit shift register; all transmit operations are completed 00 = interrupt when a character is transferred to the transmit shift register (this implies there is at least one character open in the transmit buffer) bit 14 utxinv: irda ? encoder transmit polarity inversion bit if iren = 0 : 1 = u1tx idle ? 0 ? 0 = u1tx idle ? 1 ? if iren = 1 : 1 = u1tx idle ? 1 ? 0 = u1tx idle ? 0 ? bit 12 unimplemented: read as ? 0 ? bit 11 utxbrk: transmit break bit 1 = send sync break on next transmission ? start bit, followed by twelve ? 0 ? bits, followed by stop bit; cleared by hardware upon completion 0 = sync break transmission disabled or completed bit 10 utxen: transmit enable bit 1 = transmit enabled, u1tx pin controlled by uart1 0 = transmit disabled, any pending transmission is aborted and buffer is reset. u1tx pin controlled by the port register. bit 9 utxbf: transmit buffer full status bit (read-only) 1 = transmit buffer is full 0 = transmit buffer is not full, at least one more character can be written bit 8 trmt: transmit shift register empty bit (read-only) 1 = transmit shift register is empty and transmit buffer is empty (the last transmission has completed) 0 = transmit shift register is not empty, a transmission is in progress or queued bit 7-6 urxisel<1:0>: receive interrupt mode selection bits 11 = interrupt is set on rsr transfer, making the receive buffer full (i.e., has 4 data characters) 10 = interrupt is set on rsr transfer, making the receive buffer 3/4 full (i.e., has 3 data characters) 0x = interrupt is set when any character is received and transferred from the rsr to the receive buffer. receive buffer has one or more characters.
? 2009 microchip technology inc. preliminary ds39937b-page 139 pic24f04ka201 family bit 5 adden: address character detect bit (bit 8 of received data = 1 ) 1 = address detect mode enabled. if 9-bit mode is not selected, this does not take effect. 0 = address detect mode disabled bit 4 ridle: receiver idle bit (read-only) 1 = receiver is idle 0 = receiver is active bit 3 perr: parity error status bit (read-only) 1 = parity error has been detected for the current character (character at the top of the receive fifo) 0 = parity error has not been detected bit 2 ferr: framing error status bit (read-only) 1 = framing error has been detected for the current character (character at the top of the receive fifo) 0 = framing error has not been detected bit 1 oerr: receive buffer overrun error status bit (clear/read-only) 1 = receive buffer has overflowed 0 = receive buffer has not overflowed (clearing a previously set oerr bit ( 1 0 transition) will reset the receiver buffer and the rsr to the empty state) bit 0 urxda: receive buffer data available bit (read-only) 1 = receive buffer has data; at least one more character can be read 0 = receive buffer is empty register 17-2: u1sta: uart1 status and control register (continued)
pic24f04ka201 family ds39937b-page 140 preliminary ? 2009 microchip technology inc. register 17-3: u1txreg: uart1 transmit register u-x u-x u-x u-x u-x u-x u-x w-x ? ? ? ? ? ? ?utx8 bit 15 bit 8 w-x w-x w-x w-x w-x w-x w-x w-x utx7 utx6 utx5 utx4 utx3 utx2 utx1 utx0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 utx8: data of the transmitted character bit (in 9-bit mode) bit 7-0 utx<7:0>: data of the transmitted character bits register 17-4: u1rxreg: uart1 receive register u-0 u-0 u-0 u-0 u-0 u-0 u-0 r-0, hsc ? ? ? ? ? ? ?urx8 bit 15 bit 8 r-0, hsc r-0, hsc r-0, hsc r-0, hsc r-0, hsc r-0, hsc r-0, hsc r-0, hsc urx7 urx6 urx5 urx4 urx3 urx2 urx1 urx0 bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-9 unimplemented: read as ? 0 ? bit 8 urx8: data of the received character bit (in 9-bit mode) bit 7-0 urx<7:0>: data of the received character bits
? 2009 microchip technology inc. preliminary ds39937b-page 141 pic24f04ka201 family 18.0 high/low-voltage detect (hlvd) the high/low-voltage detect module (hlvd) is a programmable circuit that allows the user to specify both the device voltage trip point and the direction of change. an interrupt flag is set if the device experiences an excursion past the trip point in the direction of change. if the interrupt is enabled, the program execution will branch to the interrupt vector address and the software can then respond to the interrupt. the hlvd control register (see register 18-1) completely controls the operation of the hlvd module. this allows the circuitry to be ?turned off? by the user under software control, which minimizes the current consumption for the device. figure 18-1: high/low-voltage de tect (hlvd) module block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the high/low-voltage detect, refer to the ?pic24f family reference manual? , section 36. ?high-level integration with programmable high/low-voltage detect (hlvd)? (ds39725). set v dd 16-to-1 mux hlvden hlvdl<3:0> hlvdin v dd externally generated trip point hlvdif hlvden internal voltage reference vdir 1.2v typical
pic24f04ka201 family ds39937b-page 142 preliminary ? 2009 microchip technology inc. register 18-1: hlvdcon: high/low-v oltage detect control register r/w-0 u-0 r/w-0 u-0 u-0 u-0 u-0 u-0 hlvden ?hlsidl ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 vdir bgvst irvst ? hlvdl3 hlvdl2 hlvdl1 hlvdl0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 hlvden: high/low-voltage detect power enable bit 1 = hlvd enabled 0 = hlvd disabled bit 14 unimplemented: read as ? 0 ? bit 13 hlsidl: hlvd stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-8 unimplemented: read as ? 0 ? bit 7 vdir: voltage change direction select bit 1 = event occurs when voltage equals or exceeds trip point (hlvdl<3:0>) 0 = event occurs when voltage equals or falls below trip point (hlvdl<3:0>) bit 6 bgvst: band gap voltage stable flag bit 1 = indicates that the band gap voltage is stable 0 = indicates that the band gap voltage is unstable bit 5 irvst: internal reference voltage stable flag bit 1 = indicates that the internal reference voltage is stable and the high-voltage detect logic generates the interrupt flag at the specified voltage range 0 = indicates that the internal reference voltage is unstable and the high-voltage detect logic will not generate the interrupt flag at the specified voltage range, and the hlvd interrupt should not be enabled bit 4 unimplemented: read as ? 0 ? bit 3-0 hlvdl<3:0>: high/low-voltage detection limit bits 1111 = external analog input is used (input comes from the hlvdin pin) 1110 = trip point 1 (1) 1101 = trip point 2 (1) 1100 = trip point 3 (1) . . . 0000 = trip point 15 (1) note 1: for actual trip point, refer to section 26.0 ?electrical characteristics? .
? 2009 microchip technology inc. preliminary ds39937b-page 143 pic24f04ka201 family 19.0 10-bit high-speed a/d converter the 10-bit a/d converter has the following key features: ? successive approximation (sar) conversion ? conversion speeds of up to 500 ksps ? 9 analog input pins ? external voltage reference input pins ? internal band gap reference inputs ? automatic channel scan mode ? selectable conversion trigger source ? 16-word conversion result buffer ? selectable buffer fill modes ? four result alignment options ? operation during cpu sleep and idle modes on all pic24f04ka201 family devices, the 10-bit a/d converter has nine analog input pins, designated an0 through an5 and an10 through an12. in addition, there are two analog input pins for external voltage reference connections (v ref + and v ref -). these voltage reference inputs may be shared with other analog input pins. a block diagram of the a/d converter is displayed in figure 19-1. to perform an a/d conversion: 1. configure the a/d module: a) configure port pins as analog inputs and/or select band gap reference inputs (ad1pcfg<15:13>, ad1pcfg<9:6>). b) select voltage reference source to match expected range on analog inputs (ad1con2<15:13>). c) select the analog conversion clock to match the desired data rate with the processor clock (ad1con3<7:0>). d) select the appropriate sample/conversion sequence (ad1con1<7:5> and ad1con3<12:8>). e) select how conversion results are presented in the buffer (ad1con1<9:8>). f) select interrupt rate (ad1con2<5:2>). g) turn on a/d module (ad1con1<15>). 2. configure a/d interrupt (if required): a) clear the ad1if bit. b) select a/d interrupt priority. note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the 10-bit high-speed a/d converter, refer to the ?pic24f family reference manual? , section 17. ?10-bit a/d converter? (ds39705).
pic24f04ka201 family ds39937b-page 144 preliminary ? 2009 microchip technology inc. figure 19-1: 10-bit high-speed a/d converter block diagram comparator 10-bit sar conversion logic v ref + dac an12 an10 an11 an4 an5 an0 an1 an2 an3 v ref - sample control s/h av ss av dd adc1buf0: adc1buff ad1con1 ad1con2 ad1con3 ad1chs ad1pcfg control logic data formatting input mux control conversion control pin config control internal data bus 16 v r + v r - mux a mux b v inh v inl v inh v inh v inl v inl v bg v bg /2 ad1cssl v r + v r - v r select an1 an1
? 2009 microchip technology inc. preliminary ds39937b-page 145 pic24f04ka201 family register 19-1: ad1con1: a/d control register 1 r/w-0 u-0 r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 adon (1) ?adsidl ? ? ?form1form0 bit 15 bit 8 r/w -0 r/w -0 r/w-0 u-0 u-0 r/w-0 r/w -0, hsc r/w -0, hsc ssrc2 ssrc1 ssrc0 ? ? asam samp done bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 adon: a/d operating mode bit (1) 1 = a/d converter module is operating 0 = a/d converter is off bit 14 unimplemented: read as ? 0 ? bit 13 adsidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12-10 unimplemented: read as ? 0 ? bit 9-8 form<1:0>: data output format bits 11 = signed fractional ( sddd dddd dd00 0000 ) 10 = fractional ( dddd dddd dd00 0000 ) 01 = signed integer ( ssss sssd dddd dddd ) 00 = integer ( 0000 00dd dddd dddd ) bit 7-5 ssrc<2:0>: conversion trigger source select bits 111 = internal counter ends sampling and starts conversion (auto-convert) 110 = ctmu event ends sampling and starts conversion 101 = reserved 100 = reserved 011 = reserved 010 = timer3 compare ends sampling and starts conversion 001 = active transition on int0 pin ends sampling and starts conversion 000 = clearing samp bit ends sampling and starts conversion bit 4-3 unimplemented: read as ? 0 ? bit 2 asam: a/d sample auto-start bit 1 = sampling begins immediately after last conversion completes; samp bit is auto-set 0 = sampling begins when samp bit is set bit 1 samp: a/d sample enable bit 1 = a/d sample/hold amplifier is sampling input 0 = a/d sample/hold amplifier is holding bit 0 done: a/d conversion status bit 1 = a/d conversion is done 0 = a/d conversion is not done note 1: values of adc1bufn registers will not retain their values once the adon bit is cleared. read out the conversion values from the buffer before disabling the module.
pic24f04ka201 family ds39937b-page 146 preliminary ? 2009 microchip technology inc. register 19-2: ad1con2: a/d control register 2 r/w-0 r/w-0 r/w-0 r/w-0 u-0 r/w-0 u-0 u-0 vcfg2 vcfg1 vcfg0 offcal (1) ? cscna ? ? bit 15 bit 8 r-0, hsc u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 bufs ? smpi3 smpi2 smpi1 smpi0 bufm alts bit 7 bit 0 legend: u = unimplemented bit, read as ?0? hsc = hardware settable/clearable bit r = readable bit w = writable bit r = reserved bit? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-13 vcfg<2:0>: voltage reference configuration bits bit 12 offcal: offset calibration bit (1) 1 = converts to get the offset calibration value 0 = coverts to get the actual input value bit 11 unimplemented: read as ? 0 ? bit 10 cscna: scan input selections for ch0+ s/h input for mux a input multiplexer setting bit 1 = scan inputs 0 = do not scan inputs bit 9-8 unimplemented: read as ? 0 ? bit 7 bufs: buffer fill status bit (valid only when bufm = 1 ) 1 = a/d is currently filling buffer, 08-0f, user should access data in 00-07 0 = a/d is currently filling buffer, 00-07, user should access data in 08-0f bit 6 unimplemented: read as ? 0 ? bit 5-2 smpi<3:0>: sample/convert sequences per interrupt selection bits 1111 = interrupts at the completion of conversion for each 16 th sample/convert sequence 1110 = interrupts at the completion of conversion for each 15 th sample/convert sequence . . . 0001 = interrupts at the completion of conversion for each 2 nd sample/convert sequence 0000 = interrupts at the completion of conversion for each sample/convert sequence bit 1 bufm: buffer mode select bit 1 = buffer configured as two 8-word buffers (adc1bufn<15:8> and adc1bufn<7:0>) 0 = buffer configured as one 16-word buffer (adc1bufn<15:0>) bit 0 alts: alternate input sample mode select bit 1 = uses mux a input multiplexer settings for first sample, then alternates between mux b and mux a input multiplexer settings for all subsequent samples 0 = always uses mux a input multiplexer settings note 1: when the offcal bit is set, inputs are disconnected and tied to av ss . this sets the inputs of the a/d to zero. then, the user can perform a conversion. use of the calibration mode is not affected by ad1pcfg contents nor channel input selection. any analog input switches are disconnected from the a/d converter in this mode. the conversion result is stored by the user software and used to compensate subsequent conversions. this can be done by adding the two?s complement of the result obtained with the offcal bit set to all normal a/d conversions. vcfg<2:0> v r +v r - 000 av dd av ss 001 external v ref + pin av ss 010 av dd external v ref - pin 011 external v ref + pin external v ref - pin 1xx av dd av ss
? 2009 microchip technology inc. preliminary ds39937b-page 147 pic24f04ka201 family register 19-3: ad1con3: a/d control register 3 r/w-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 adrc ? ? samc4 samc3 samc2 samc1 samc0 bit 15 bit 8 u -0 u -0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? adcs5 adcs4 adcs3 adcs2 adcs1 adcs0 bit 7 bit 0 legend: r = reserved bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 adrc: a/d conversion clock source bit 1 = a/d internal rc clock 0 = clock derived from system clock bit 14-13 unimplemented: read as ? 0 ? bit 12-8 samc<4:0>: auto-sample time bits 11111 = 31 t ad 00001 = 1 t ad 00000 = 0 t ad (not recommended) bit 7-6 unimplemented: read as ? 0 ? bit 5-0 adcs<5:0>: a/d conversion clock select bits 111111 = 32 ? t cy 000001 = t cy 000000 = t cy /2
pic24f04ka201 family ds39937b-page 148 preliminary ? 2009 microchip technology inc. - register 19-4: ad1chs: a/d input select register r/w-0 u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 ch0nb ? ? ? ch0sb3 ch0sb2 ch0sb1 ch0sb0 bit 15 bit 8 r/w -0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ch0na ? ? ch0sa4 ch0sa3 ch0sa2 ch0sa1 ch0sa0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ch0nb: channel 0 negative input select for mux b multiplexer setting bit 1 = channel 0 negative input is an1 0 = channel 0 negative input is v r - bit 14-12 unimplemented: read as ? 0 ? bit 11-8 ch0sb<3:0>: channel 0 positive input select for mux b multiplexer setting bits 1111 = channel 0 positive input is band gap reference (v bg ) 1110 = channel 0 positive input is band gap, divided by two, reference (v bg /2) 1101 = no channels connected (actual adc mux switch activates but input floats); used for ctmu 1100 = channel 0 positive input is an12 1011 = channel 0 positive input is an11 1010 = channel 0 positive input is an10 1001 = reserved 1000 = reserved 0110 = av dd 0110 = av ss 0101 = channel 0 positive input is an5 0100 = channel 0 positive input is an4 0010 = channel 0 positive input is an3 0010 = channel 0 positive input is an2 0001 = channel 0 positive input is an1 0000 = channel 0 positive input is an0 bit 7 ch0na: channel 0 negative input select for mux a multiplexer setting bit 1 = channel 0 negative input is an1 0 = channel 0 negative input is v r - bit 6-5 unimplemented: read as ? 0 ? bit 4-0 ch0sa<4:0>: channel 0 positive input select for sample a bits 1111 = channel 0 positive input is band gap reference (v bg ) 1110 = channel 0 positive input is band gap, divided by two, reference (v bg /2) 1101 = no channels connected (actual adc mux switch activates but input floats); used for ctmu 1100 = channel 0 positive input is an12 1011 = channel 0 positive input is an11 1010 = channel 0 positive input is an10 1001 = reserved 1000 = reserved 0110 = av dd 0110 = av ss 0101 = channel 0 positive input is an5 0100 = channel 0 positive input is an4 0010 = channel 0 positive input is an3 0010 = channel 0 positive input is an2 0001 = channel 0 positive input is an1 0000 = channel 0 positive input is an0
? 2009 microchip technology inc. preliminary ds39937b-page 149 pic24f04ka201 family register 19-5: ad1pcfg: a/d port configuration register u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 u-0 u-0 ? ? ? pcfg12 pcfg11 pcfg10 ? ? bit 15 bit 8 u -0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? pcfg5 pcfg4 pcfg3 pcfg2 pcfg1 pcfg0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-13 unimplemented: read as ? 0 ? bit 12-10 pcfg<12:10>: analog input pin configuration control bits 1 = pin for corresponding analog channel is configured in digital mode; i/o port read enabled 0 = pin configured in analog mode; i/o port read disabled; a/d samples pin voltage bit 9-6 unimplemented: read as ? 0 ? bit 5-0 pcfg<5:0>: analog input pin configuration control bits 1 = pin for corresponding analog channel is configured in digital mode; i/o port read enabled 0 = pin configured in analog mode; i/o port read disabled; a/d samples pin voltage register 19-6: ad1cssl: a/d input scan select register (low) u-0 u-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? ? cssl12 cssl11 cssl10 ? ? bit 15 bit 8 u -0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ? ? cssl5 cssl4 cssl3 cssl2 cssl1 cssl0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-13 unimplemented: read as ? 0 ? bit 12-10 cssl<12:10>: a/d input pin scan selection bits 1 = corresponding analog channel selected for input scan 0 = analog channel omitted from input scan bit 9-6 unimplemented: read as ? 0 ? bit 5-0 cssl<5:0>: a/d input pin scan selection bits 1 = corresponding analog channel selected for input scan 0 = analog channel omitted from input scan
pic24f04ka201 family ds39937b-page 150 preliminary ? 2009 microchip technology inc. equation 19-1: a/d conversion clock period (1) figure 19-2: 10-bit a/d converter analog input model note 1: based on t cy = 2 * t osc , doze mode and pll are disabled. t ad = t cy ? (adcs + 1) t ad t cy adcs = ? 1 c pin va rs anx v t = 0.6v v t = 0.6v i leakage r ic 250w sampling switch r ss c hold = dac capacitance v ss v dd = 4.4 pf (typical) 500 na legend: c pin v t i leakage r ic r ss c hold = input capacitance = threshold voltage = leakage current at the pin due to = interconnect resistance = sampling switch resistance = sample/hold capacitance (from dac) various junctions note: c pin value depends on device package and is not tested. effect of c pin negligible if rs 5 k . r ss 5 k (typical) 6-11 pf (typical)
? 2009 microchip technology inc. preliminary ds39937b-page 151 pic24f04ka201 family figure 19-3: a/d transfer function 10 0000 0001 (513) 10 0000 0010 (514) 10 0000 0011 (515) 01 1111 1101 (509) 01 1111 1110 (510) 01 1111 1111 (511) 11 1111 1110 (1022) 11 1111 1111 (1023) 00 0000 0000 (0) 00 0000 0001 (1) output code 10 0000 0000 (512) (v inh ? v inl ) v r - v r + ? v r - 1024 512 * (v r + ? v r -) 1024 v r + v r - + v r - + 1023 * (v r + ? v r -) 1024 v r - + 0 (binary (decimal)) voltage level
pic24f04ka201 family ds39937b-page 152 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 153 pic24f04ka201 family 20.0 comparator module the comparator module provides two dual input comparators. the inputs to the comparator can be configured to use any one of four external analog inputs, as well as a voltage reference input from either the internal band gap reference divided by 2 (v bg /2) or the comparator voltage reference generator. the comparator outputs may be directly connected to the cxout pins. when the respective coe equals ? 1 ?, the i/o pad logic makes the unsynchronized output of the comparator available on the pin. a simplified block diagram of the module is displayed in figure 20-1. diagrams of the possible individual comparator configurations are displayed in figure 20-2. each comparator has its own control register, cmxcon (register 20-1), for enabling and configuring its operation. the output and event status of all three comparators is provided in the cmstat register (register 20-2). figure 20-1: comparator module block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the comparator module, refer to the ?pic24f family reference manual? , section 19. ?comparator module? (ds39710). c1 v in - v in + c x inb c x ina cv ref v bg /2 c2 v in - v in + coe c1out pin cpol trigger/interrupt logic cevt evpol<1:0> cout input select logic cch<1:0> cref coe c2out pin cpol trigger/interrupt logic cevt evpol<1:0> cout
pic24f04ka201 family ds39937b-page 154 preliminary ? 2009 microchip technology inc. figure 20-2: individual comparator configurations cx v in - v in + off (read as ? 0 ?) comparator off con = 0 , cref = x , cch<1:0> = xx comparator cxinb > cxina compare con = 1 , cref = 0 , cch<1:0> = 00 coe cxout cx v in - v in + coe c x inb c x ina comparator v bg > cxina compare con = 1 , cref = 0 , cch<1:0> = 11 cx v in - v in + coe v bg /2 c x ina comparator cxinb > cv ref compare con = 1 , cref = 1 , cch<1:0> = 00 cx v in - v in + coe c x inb cv ref comparator v bg > cv ref compare con = 1 , cref = 1 , cch<1:0> = 11 cx v in - v in + coe v bg /2 cv ref pin cxout pin cxout pin cxout pin cxout pin - - - - -
? 2009 microchip technology inc. preliminary ds39937b-page 155 pic24f04ka201 family register 20-1: cmxcon: comp arator x control registers r/w-0 r/w-0 r/w-0 r/w-0 u-0 u-0 r/w-0 r-0 con coe cpol clpwr ? ? cevt cout bit 15 bit 8 r/w-0 r/w-0 u-0 r/w-0 u-0 u-0 r/w-0 r/w-0 evpol1 evpol0 ? cref ? ? cch1 cch0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 con: comparator enable bit 1 = comparator is enabled 0 = comparator is disabled bit 14 coe: comparator output enable bit 1 = comparator output is present on the cxout pin 0 = comparator output is internal only bit 13 cpol: comparator output polarity select bit 1 = comparator output is inverted 0 = comparator output is not inverted bit 12 clpwr: comparator low-power mode select bit 1 = comparator operates in low-power mode 0 = comparator does not operate in low-power mode bit 11-10 unimplemented: read as ? 0 ? bit 9 cevt: comparator event bit 1 = comparator event defined by evpol<1:0> has occurred; subsequent triggers and interrupts are disabled until the bit is cleared 0 = comparator event has not occurred bit 8 cout: comparator output bit when cpol = 0 : 1 =v in + > v in - 0 =v in + < v in - when cpol = 1 : 1 =v in + < v in - 0 =v in + > v in - bit 7-6 evpol<1:0>: trigger/event/interrupt polarity select bits 11 = trigger/event/interrupt generated on any change of the comparator output (while cevt = 0 ) 10 = trigger/event/interrupt generated on transition of the comparator output: if cpol = 0 ( non-inverted polarity): high-to-low transition only. if cpol = 1 ( inverted polarity): low-to-high transition only. 01 = trigger/event/interrupt generated on transition of comparator output: if cpol = 0 ( non-inverted polarity): low-to-high transition only. if cpol = 1 ( inverted polarity): high-to-low transition only. 00 = trigger/event/interrupt generation is disabled bit 5 unimplemented: read as ? 0 ? bit 4 cref: comparator reference select bits (non-inverting input) 1 = non-inverting input connects to internal cv ref voltage 0 = non-inverting input connects to cxina pin bit 3-2 unimplemented: read as ? 0 ? bit 1-0 cch<1:0>: comparator channel select bits 11 = inverting input of comparator connects to v bg /2 00 = inverting input of comparator connects to cxinb pin
pic24f04ka201 family ds39937b-page 156 preliminary ? 2009 microchip technology inc. register 20-2: cmstat: comparat or module status register r/w-0 u-0 u-0 u-0 u-0 u-0 r-0, hsc r-0, hsc cmidl ? ? ? ? ? c2evt c1evt bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 r-0, hsc r-0, hsc ? ? ? ? ? ? c2out c1out bit 7 bit 0 legend: hsc = hardware settable/clearable bit r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 cmidl: comparator stop in idle mode bit 1 = when device enters idle mode, the module does not generate interrupts; it is still enabled 0 = continue operation of all enabled comparators in idle mode bit 14-10 unimplemented: read as ? 0 ? bit 9 c2evt: comparator 2 event status bit (read-only) shows the current event status of comparator 2 (cm2con<9>). bit 8 c1evt: comparator 1 event status bit (read-only) shows the current event status of comparator 1 (cm1con<9>). bit 7-2 unimplemented: read as ? 0 ? bit 1 c2out: comparator 2 output status bit (read-only) shows the current output of comparator 2 (cm2con<8>). bit 0 c1out: comparator 1 output status bit (read-only) shows the current output of comparator 1 (cm1con<8>).
? 2009 microchip technology inc. preliminary ds39937b-page 157 pic24f04ka201 family 21.0 comparator voltage reference 21.1 configuring the comparator voltage reference the comparator voltage reference module is controlled through the cvrcon register (register 21-1). the comparator voltage reference provides two ranges of output voltage, each with 16 distinct levels. the range to be used is selected by the cvrr bit (cvrcon<5>). the primary difference between the ranges is the size of the steps selected by the cv ref selection bits (cvr<3:0>), with one range offering finer resolution. the comparator reference supply voltage can come from either v dd and v ss , or the external v ref + and v ref -. the voltage source is selected by the cvrss bit (cvrcon<4>). the settling time of the comparator voltage reference must be considered when changing the cv ref output. figure 21-1: comparator volt age reference block diagram note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the comparator voltage reference, refer to the ?pic24f family reference manual? , section 20. ?comparator voltage reference module? (ds39709). 16-to-1 mux cvr<3:0> 8r r cvren cvrss = 0 av dd v ref + cvrss = 1 8r cvrss = 0 v ref - cvrss = 1 r r r r r r 16 steps cvrr cv ref av ss
pic24f04ka201 family ds39937b-page 158 preliminary ? 2009 microchip technology inc. register 21-1: cvrcon: comparator vo ltage reference control register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 cvren cvroe cvrr cvrss cvr3 cvr2 cvr1 cvr0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-8 unimplemented: read as ? 0 ? bit 7 cvren: comparator voltage reference enable bit 1 =cv ref circuit powered on 0 =cv ref circuit powered down bit 6 cvroe: comparator v ref output enable bit 1 =cv ref voltage level is output on cv ref pin 0 =cv ref voltage level is disconnected from cv ref pin bit 5 cvrr: comparator v ref range selection bit 1 =cv rsrc range should be 0 to 0.625 cv rsrc with cv rsrc /24 step size 0 =cv rsrc range should be 0.25 to 0.719 cv rsrc with cv rsrc /32 step size bit 4 cvrss: comparator v ref source selection bit 1 = comparator reference source cv rsrc = v ref + ? v ref - 0 = comparator reference source cv rsrc = av dd ? av ss bit 3-0 cvr3:cvr0: comparator v ref value selection 0 cvr<3:0> 15 bits w hen cvrr = 1 and cvrss = 0 : cv ref = (cvr<3:0>/24) * (cv rsrc ) w hen cvrr = 0 and cvrss = 0 : cv ref = 1/4 (cv rsrc ) + (cvr<3:0>/32) * (cv rsrc ) w hen cvrr = 1 and cvrss = 1 : cv ref = ((cvr<3:0>/24) * (cv rsrc )) + v ref - w hen cvrr = 0 and cvrss = 1 : cv ref = (1/4 (cv rsrc ) + (cvr<3:0>/32) * (cv rsrc )) + v ref -
? 2009 microchip technology inc. preliminary ds39937b-page 159 pic24f04ka201 family 22.0 charge time measurement unit (ctmu) the charge time measurement unit (ctmu) is a flexible analog module that provides charge measure- ment, accurate differential time measurement between pulse sources and asynchronous pulse generation. its key features include: ? four edge input trigger sources ? polarity control for each edge source ? control of edge sequence ? control of response to edges ? time measurement resolution of one nanosecond ? accurate current source suitable for capacitive measurement together with other on-chip analog modules, the ctmu can be used to precisely measure time, measure capacitance, measure relative changes in capacitance, or generate output pulses that are independent of the system clock. the ctmu module is ideal for interfacing with capacitive-based touch sensors. the ctmu is controlled through two registers, ctmucon and ctmuicon. ctmucon enables the module, and controls edge source selection, edge source polarity selection, and edge sequencing. the ctmuicon register selects the current range of current source and trims the current. 22.1 measuring capacitance the ctmu module measures capacitance by generating an output pulse with a width equal to the time between edge events on two separate input channels. the pulse edge events to both input channels can be selected from four sources: two internal peripheral modules (oc1 and timer1) and two external pins (ctedg1 and ctedg2). this pulse is used with the module?s precision current source to calculate capacitance according to the relationship: for capacitance measurements, the a/d converter samples an external capacitor (c app ) on one of its input channels after the ctmu output?s pulse. a precision resistor (r pr ) provides current source calibration on a second a/d channel. after the pulse ends, the converter determines the voltage on the capacitor. the actual calculation of capacitance is performed in software by the application. figure 22-1 displays the external connections used for capacitance measurements, and how the ctmu and a/d modules are related in this application. this example also shows the edge events coming from timer1, but other configurations using external edge sources are possible. a detailed discussion on measuring capacitance and time with the ctmu module is provided in the ? pic24f family reference manual? . figure 22-1: typical connections and internal configuration for capacitance measurement note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the charge measurement unit, refer to the ?pic24f family reference manual? , section 11. ?charge time measurement unit (ctmu)? (ds39724). ci dv dt ------ - ? = pic24f device a/d converter ctmu anx c app output pulse edg1 edg2 r pr an y timer1 current source
pic24f04ka201 family ds39937b-page 160 preliminary ? 2009 microchip technology inc. 22.2 measuring time time measurements on the pulse width can be similarly performed using the a/d module?s internal capacitor (c ad ) and a precision resistor for current calibration. figure 22-2 displays the external connections used for time measurements, and how the ctmu and a/d modules are related in this application. this example also shows both edge events coming from the external ctedg pins, but other configurations using internal edge sources are possible. 22.3 pulse generation and delay the ctmu module can also generate an output pulse with edges that are not synchronous with the device?s system clock. more specifically, it can generate a pulse with a programmable delay from an edge event input to the module. when the module is configured for pulse generation delay by setting the tgen bit (ctmucon<12>), the internal current source is connected to the b input of comparator 2. a capacitor (c delay ) is connected to the comparator 2 pin, c2inb, and the comparator voltage reference, cv ref , is connected to c2ina. cv ref is then configured for a specific trip point. the module begins to charge c delay when an edge event is detected. when c delay charges above the cv ref trip point, a pulse is output on ctpls. the length of the pulse delay is determined by the value of c delay and the cv ref trip point. figure 22-3 shows the external connections for pulse generation, as well as the relationship of the different analog modules required. while ctedg1 is shown as the input pulse source, other options are available. a detailed discussion on pulse generation with the ctmu module is provided in the ? pic24f family reference manual? . figure 22-2: typical co nnections and internal configuration for time measurement figure 22-3: typical co nnections and internal co nfiguration for pulse delay generation pic24f device a/d converter ctmu ctedg1 ctedg2 anx output pulse edg1 edg2 c ad r pr current source c2 cv ref ctpls pic24f device current source comparator ctmu ctedg1 c2inb c delay edg1 -
? 2009 microchip technology inc. preliminary ds39937b-page 161 pic24f04ka201 family register 22-1: ctmucon: ctmu control register r/w-0 u-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 ctmuen ? ctmusidl tgen edgen edgseqen idissen cttrig bit 15 bit 8 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 edg2pol edg2sel1 edg2sel0 edg1pol ed g1sel1 edg1sel0 edg2stat edg1stat bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15 ctmuen: ctmu enable bit 1 = module is enabled 0 = module is disabled bit 14 unimplemented: read as ? 0 ? bit 13 ctmusidl: stop in idle mode bit 1 = discontinue module operation when device enters idle mode 0 = continue module operation in idle mode bit 12 tgen: time generation enable bit 1 = enables edge delay generation 0 = disables edge delay generation bit 10 edgen: edge enable bit 1 = edges are not blocked 0 = edges are blocked bit 10 edgseqen: edge sequence enable bit 1 = edge 1 event must occur before edge 2 event can occur 0 = no edge sequence is needed bit 9 idissen: analog current source control bit 1 = analog current source output is grounded 0 = analog current source output is not grounded bit 8 cttrig: trigger control bit 1 = trigger output is enabled 0 = trigger output is disabled bit 7 edg2pol: edge 2 polarity select bit 1 = edge 2 programmed for a positive edge response 0 = edge 2 programmed for a negative edge response bit 6-5 edg2sel<1:0>: edge 2 source select bits 11 = cted1 pin 10 = cted2 pin 01 = oc1 module 00 = timer1 module bit 4 edg1pol: edge 1 polarity select bit 1 = edge 1 programmed for a positive edge response 0 = edge 1 programmed for a negative edge response
pic24f04ka201 family ds39937b-page 162 preliminary ? 2009 microchip technology inc. bit 3-2 edg1sel<1:0>: edge 1 source select bits 11 = cted1 pin 10 = cted2 pin 01 = oc1 module 00 = timer1 module bit 1 edg2stat: edge 2 status bit 1 = edge 2 event has occurred 0 = edge 2 event has not occurred bit 0 edg1stat: edge 1 status bit 1 = edge 1 event has occurred 0 = edge 1 event has not occurred register 22-1: ctmuco n: ctmu control register (continued) register 22-2: ctmuicon: ctmu current control register r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 r/w-0 itrim5 itrim4 itrim3 itrim2 itrim1 itrim0 irng1 irng0 bit 15 bit 8 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 15-10 itrim<5:0>: current source trim bits 011111 = maximum positive change from nominal current 011110 . . . 000001 = minimum positive change from nominal current 000000 = nominal current output specified by irng<1:0> 111111 = minimum negative change from nominal current . . . 100010 100001 = maximum negative change from nominal current bit 9-8 irng<1:0>: current source range select bits 11 = 100 base current 10 = 10 base current 01 = base current level (0.55 a nominal) 00 = current source disabled bit 7-0 unimplemented: read as ? 0 ?
? 2009 microchip technology inc. preliminary ds39937b-page 163 pic24f04ka201 family 23.0 special features pic24f04ka201 family devices include several features intended to maximize application flexibility and reliability, and minimize cost through elimination of external components. these are: ? flexible configuration ? watchdog timer (wdt) ? code protection ? in-circuit serial programming? (icsp?) ? in-circuit emulation 23.1 configuration bits the configuration bits can be programmed (read as ? 0 ?), or left unprogrammed (read as ? 1 ?), to select various device configurations. these bits are mapped starting at program memory location, f80000h. a complete list is provided in table 23-1. a detailed explanation of the various bit functions is provided in register 23-1 through register 23-7. the address, f80000h, is beyond the user program memory space. in fact, it belongs to the configuration memory space (800000h-ffffffh), which can only be accessed using table reads and table writes. table 23-1: configuration registers locations register 23-1: fgs: general se gment configuration register note: this data sheet summarizes the features of this group of pic24f devices. it is not intended to be a comprehensive reference source. for more information on the watchdog timer, high-level device integration and programming diagnostics, refer to the individual sections of the ?pic24f family reference manual? provided below : ? section 9. ?watchdog timer (wdt)? (ds39697) ? section 36. ?high- level integration with programmabl e high/low-voltage detect (hlvd)? (ds39725) ? section 33. ?programming and diagnostics? (ds39716) configuration register address fgs f80004 foscsel f80006 fosc f80008 fwdt f8000a fpor f8000c ficd f8000e fds f80010 u-0 u-0 u-0 u-0 u-0 u-0 r/c-1 r/c-1 ? ? ? ? ? ? gss0 gwrp bit 7 bit 0 legend: r = readable bit c = clearable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 unimplemented: read as ? 0 ? bit 1 gss0: general segment code flash code protection bit 1 = no protection 0 = standard security enabled bit 0 gwrp : general segment code flash write protection bit 1 = general segment may be written 0 = general segment is write-protected
pic24f04ka201 family ds39937b-page 164 preliminary ? 2009 microchip technology inc. register 23-2: foscsel: oscillator selection configuration register r/p-1 u-0 u-0 u-0 u-0 r/p-1 r/p-1 r/p-1 ieso ? ? ? ? fnosc2 fnosc1 fnosc0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 ieso: internal external switchover bit 1 = internal external switchover mode enabled (two-speed start-up enabled) 0 = internal external switchover mode disabled (two-speed start-up disabled) bit 6-3 unimplemented: read as ? 0 ? bit 2-0 fnosc<2:0>: oscillator selection bits 000 = fast rc oscillator (frc) 001 = fast rc oscillator with divide-by-n with pll module (frcdiv+pll) 010 = primary oscillator (xt, hs, ec) 011 = primary oscillator with pll module (hs+pll, ec+pll) 100 = secondary oscillator (sosc) 101 = low-power rc oscillator (lprc) 110 = 500 khz low-power frc oscillator with divide-by-n (lpfrcdiv) 111 = 8 mhz frc oscillator with divide-by-n (frcdiv)
? 2009 microchip technology inc. preliminary ds39937b-page 165 pic24f04ka201 family register 23-3: fosc: oscilla tor configuration register r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 fcksm1 fcksm0 soscsel poscfreq1 poscfreq0 osciofnc poscmd1 poscmd0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-6 fcksm<1:0>: clock switching and monitor selection configuration bits 1x = clock switching is disabled, fail-safe clock monitor is disabled 01 = clock switching is enabled, fail-safe clock monitor is disabled 00 = clock switching is enabled, fail-safe clock monitor is enabled bit 5 soscsel: secondary oscillator select bit 1 = secondary oscillator configured for high-power operation 0 = secondary oscillator configured for low-power operation bit 4-3 poscfreq<1:0>: primary oscillator frequency range configuration bits 11 = primary oscillator/external clock input frequency greater than 8 mhz 10 = primary oscillator/external clock input frequency between 100 khz and 8 mhz 01 = primary oscillator/external clock input frequency less than 100 khz 00 = reserved; do not use bit 2 osciofnc: clko enable configuration bit 1 = clko output signal active on the osco pin; primary oscillator must be disabled or configured for the external clock mode (ec) for the clko to be active (poscmd<1:0> = 11 or 00 ) 0 = clko output disabled bit 1-0 poscmd<1:0>: primary oscillator configuration bits 11 = primary oscillator disabled 10 = hs oscillator mode selected 01 = xt oscillator mode selected 00 = external clock mode selected
pic24f04ka201 family ds39937b-page 166 preliminary ? 2009 microchip technology inc. register 23-4: fwdt: watchdog timer configuration register r/p-1 r/p-1 u-0 r/p-1 r/p-1 r/p-1 r/p-1 r/p-1 fwdten windis ? fwpsa wdtps3 wdtps2 wdtps1 wdtps0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 fwdten: watchdog timer enable bit 1 = wdt enabled 0 = wdt disabled (control is placed on the swdten bit) bit 6 windis: windowed watchdog timer disable bit 1 = standard wdt selected; windowed wdt disabled 0 = windowed wdt enabled bit 5 unimplemented: read as ? 0 ? bit 4 fwpsa: wdt prescaler bit 1 = wdt prescaler ratio of 1:128 0 = wdt prescaler ratio of 1:32 bit 3-0 wdtps<3:0>: watchdog timer postscale select bits 1111 = 1:32,768 1110 = 1:16,384 1101 = 1:8,192 1100 = 1:4,096 1011 = 1:2,048 1010 = 1:1,024 1001 = 1:512 1000 = 1:256 0111 = 1:128 0110 = 1:64 0101 = 1:32 0100 = 1:16 0011 = 1:8 0010 = 1:4 0001 = 1:2 0000 = 1:1
? 2009 microchip technology inc. preliminary ds39937b-page 167 pic24f04ka201 family register 23-5: fpor: rese t configuration register register 23-6: ficd: in-circuit debugger configuration register r/p-1 r/p-1 r/p-1 u-0 r/p-1 u-0 r/p-1 r/p-1 mclre (1) borv1 (2) borv0 (2) ?pwrten ? boren1 boren0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 mclre: mclr pin enable bit (1) 1 = mclr pin enabled; ra5 input pin disabled 0 = ra5 input pin enabled; mclr disabled bit 6-5 borv<1:0>: brown-out reset enable bits (2) 11 = brown-out reset set to lowest voltage 10 = brown-out reset 01 = brown-out reset set to highest voltage 00 = low-power brown-out reset occurs around 2.0v bit 4 unimplemented: read as ? 0 ? bit 3 pwrten: power-up timer enable bit 0 = pwrt disabled 1 = pwrt enabled bit 2 unimplemented: read as ? 0 ? bit 1-0 boren<1:0>: brown-out reset enable bits 11 = brown-out reset enabled in hardware; sboren bit disabled 10 = brown-out reset enabled only while device is active and disabled in sleep; sboren bit disabled 01 = brown-out reset controlled with the sboren bit setting 00 = brown-out reset disabled in hardware; sboren bit disabled note 1: the mclre fuse can only be changed when using the v pp -based icsp? mode entry. this prevents a user from accidentally locking out the device from the low-voltage test entry. 2: refer to the electrical specifications for bor voltages. u-0 u-0 u-0 u-0 u-0 u-0 r/p-1 r/p-1 ? ? ? ? ? ? ficd1 ficd0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7-2 unimplemented: read as ? 0 ? bit 1-0 ficd<1:0:> icd pin select bits 10 = pgc2/pgd2 are used for programming the device 01 = pgc3/pgd3 are used for programming the device 00 , 11 = reserved; do not use
pic24f04ka201 family ds39937b-page 168 preliminary ? 2009 microchip technology inc. register 23-7: fds: deep sleep configuration register r/p-1 r/p-1 u-0 u-0 r/p-1 r/p-1 r/p-1 r/p-1 dswdten dslpbor ? ? dswdtps3 dswdtps2 dswdtps1 dswdtps0 bit 7 bit 0 legend: r = readable bit p = programmable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 7 dswdten: deep sleep watchdog timer enable bit 1 = dswdt enabled 0 = dswdt disabled bit 6 dslpbor: deep sleep/low-power bor enable bit (does not affect operation in non deep sleep modes) 1 = deep sleep bor enabled in deep sleep 0 = deep sleep bor disabled in deep sleep bit 5-4 unimplemented: read as ? 0 ? bit 3-0 dswdtps<3:0>: deep sleep watchdog timer postscale select bits the dswdt prescaler is 32; this creates an approximate base time unit of 1 ms. 1111 = 1:2,147,483,648 (25.7 days) nominal 1110 = 1:536,870,912 (6.4 days) nominal 1101 = 1:134,217,728 (38.5 hours) nominal 1100 = 1:33,554,432 (9.6 hours) nominal 1011 = 1:8,388,608 (2.4 hours) nominal 1010 = 1:2,097,152 (36 minutes) nominal 1001 = 1:524,288 (9 minutes) nominal 1000 = 1:131,072 (135 seconds) nominal 0111 = 1:32,768 (34 seconds) nominal 0110 = 1:8,192 (8.5 seconds) nominal 0101 = 1:2,048 (2.1 seconds) nominal 0100 = 1:512 (528 ms) nominal 0011 = 1:128 (132 ms) nominal 0010 = 1:32 (33 ms) nominal 0001 = 1:8 (8.3 ms) nominal 0000 = 1:2 (2.1 ms) nominal
? 2009 microchip technology inc. preliminary ds39937b-page 169 pic24f04ka201 family register 23-8: devid: device id register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 23 bit 16 rrrrrrrr famid7 famid6 famid5 famid4 famid3 famid2 famid1 famid0 bit 15 bit 8 rrrrrrrr dev7 dev6 dev5 dev4 dev3 dev2 dev1 dev0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 23-16 unimplemented: read as ? 0 ? bit 15-8 famid<7:0>: device family identifier bits 00001011 = pic24f04ka201 family bit 7-0 dev<7:0>: individual device identifier bits 00000000 = pic24f04ka201 00000010 = pic24f04ka200 register 23-9: devrev: device revision register u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 23 bit 16 u-0 u-0 u-0 u-0 u-0 u-0 u-0 u-0 ? ? ? ? ? ? ? ? bit 15 bit 8 u-0 u-0 u-0 u-0 r r r r ? ? ? ? rev3 rev2 rev1 rev0 bit 7 bit 0 legend: r = readable bit w = writable bit u = unimplemented bit, read as ?0? -n = value at por ?1? = bit is set ?0? = bit is cleared x = bit is unknown bit 23-4 unimplemented: read as ? 0 ? bit 3-0 rev<3:0>: minor revision identifier bits
pic24f04ka201 family ds39937b-page 170 preliminary ? 2009 microchip technology inc. 23.2 watchdog timer (wdt) for the pic24f04ka201 family of devices, the wdt is driven by the lprc oscillator. when the wdt is enabled, the clock source is also enabled. the nominal wdt clock source from lprc is 31 khz. this feeds a prescaler that can be configured for either 5-bit (divide-by-32) or 7-bit (divide-by-128) operation. the prescaler is set by the fwpsa configuration bit. with a 31 khz input, the prescaler yields a nominal wdt time-out period (t wdt ) of 1 ms in 5-bit mode or 4 ms in 7-bit mode. a variable postscaler divides down the wdt prescaler output and allows for a wide range of time-out periods. the postscaler is controlled by the configuration bits, wdtps<3:0> (fwdt<3:0>), which allow the selection of a total of 16 settings, from 1:1 to 1:32,768. using the prescaler and postscaler, time-out periods ranging from 1 ms to 131 seconds can be achieved. the wdt, prescaler and postscaler are reset: ? on any device reset ? on the completion of a clock switch, whether invoked by software (i.e., setting the oswen bit after changing the nosc bits) or by hardware (i.e., fail-safe clock monitor) ? when a pwrsav instruction is executed (i.e., sleep or idle mode is entered) ? when the device exits sleep or idle mode to resume normal operation ?by a clrwdt instruction during normal execution if the wdt is enabled, it will continue to run during sleep or idle modes. when the wdt time-out occurs, the device will wake the device and code execution will continue from where the pwrsav instruction was executed. the corresponding sleep or idle bits (rcon<3:2>) will need to be cleared in software after the device wakes up. the wdt flag bit, wdto (rcon<4>), is not automatically cleared following a wdt time-out. to detect subsequent wdt events, the flag must be cleared in software. 23.2.1 windowed operation the watchdog timer has an optional fixed window mode of operation. in this windowed mode, clrwdt instructions can only reset the wdt during the last 1/4 of the programmed wdt period. a clrwdt instruction executed before that window causes a wdt reset, similar to a wdt time-out. windowed wdt mode is enabled by programming the configuration bit, windis (fwdt<6>), to ? 0 ?. 23.2.2 control register the wdt is enabled or disabled by the fwdten configuration bit. when the fwdten configuration bit is set, the wdt is always enabled. the wdt can be optionally controlled in software when the fwdten configuration bit has been programmed to ? 0 ?. the wdt is enabled in software by setting the swdten control bit (rcon<5>). the swdten control bit is cleared on any device reset. the software wdt option allows the user to enable the wdt for critical code segments and disable the wdt during non-critical segments for maximum power savings. figure 23-1: wdt block diagram note: the clrwdt and pwrsav instructions clear the prescaler and postscaler counts when executed. lprc input wdt overflow wake from sleep 31 khz prescaler postscaler fwpsa swdten fwdten reset all device resets sleep or idle mode lprc control clrwdt instr. pwrsav instr. (5-bit/7-bit) 1:1 to 1:32.768 wdtps<3:0> 1 ms/4 ms exit sleep or idle mode wdt counter transition to new clock source
? 2009 microchip technology inc. preliminary ds39937b-page 171 pic24f04ka201 family 23.3 deep sleep watchdog timer (dswdt) in pic24f04ka201 family devices, in addition to the wdt module, a dswdt module is present which runs while the device is in deep sleep, if enabled. it is driven by either the sosc or lprc oscillator. the clock source is selected by the configuration bit, dswcksel (fds<4>). the dswdt can be configured to generate a time-out at 2.1 ms to 25.7 days by selecting the respective postscaler. the postscaler can be selected by the configuration bits, dswdtps<3:0> (fds<3:0>). when the dswdt is enabled, the clock source is also enabled. dswdt is one of the sources that can wake-up the device from deep sleep mode. 23.4 program verification and code protection for all devices in the pic24f04ka201 family, code protection for the general segment is controlled by the configuration bit, gss0. this bit inhibits external reads and writes to the program memory space; this has no direct effect in normal execution mode. write protection is controlled by the gwrp bit for the general segment in the configuration word. when this bit is programmed to ? 0 ?, internal write and erase operations to program memory are blocked. 23.5 in-circuit serial programming pic24f04ka201 family microcontrollers can be serially programmed while in the end application circuit. this is simply done with two lines for clock (pgcx) and data (pgdx) and three other lines for power, ground and the programming voltage. this allows customers to manufacture boards with unprogrammed devices and then program the microcontroller just before shipping the product. this also allows the most recent firmware or a custom firmware to be programmed.
pic24f04ka201 family ds39937b-page 172 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 173 pic24f04ka201 family 24.0 development support the pic ? microcontrollers are supported with a full range of hardware and software development tools: ? integrated development environment - mplab ? ide software ? assemblers/compilers/linkers - mpasm tm assembler - mplab c18 and mplab c30 c compilers -mplink tm object linker/ mplib tm object librarian - mplab asm30 assembler/linker/library ? simulators - mplab sim software simulator ?emulators - mplab ice 2000 in-circuit emulator - mplab real ice? in-circuit emulator ? in-circuit debugger - mplab icd 2 ? device programmers - picstart ? plus development programmer - mplab pm3 device programmer - pickit? 2 development programmer ? low-cost demonstration and development boards and evaluation kits 24.1 mplab integrated development environment software the mplab ide software brings an ease of software development previously unseen in the 8/16-bit micro- controller market. the mplab ide is a windows ? operating system-based application that contains: ? a single graphical interface to all debugging tools - simulator - programmer (sold separately) - emulator (sold separately) - in-circuit debugger (sold separately) ? a full-featured editor with color-coded context ? a multiple project manager ? customizable data windows with direct edit of contents ? high-level source code debugging ? visual device initializer for easy register initialization ? mouse over variable inspection ? drag and drop variables from source to watch windows ? extensive on-line help ? integration of select third party tools, such as hi-tech software c compilers and iar c compilers the mplab ide allows you to: ? edit your source files (either assembly or c) ? one touch assemble (or compile) and download to pic mcu emulator and simulator tools (automatically updates all project information) ? debug using: - source files (assembly or c) - mixed assembly and c - machine code mplab ide supports multiple debugging tools in a single development paradigm, from the cost-effective simulators, through low-cost in-circuit debuggers, to full-featured emulators. this eliminates the learning curve when upgrading to tools with increased flexibility and power.
pic24f04ka201 family ds39937b-page 174 preliminary ? 2009 microchip technology inc. 24.2 mpasm assembler the mpasm assembler is a full-featured, universal macro assembler for all pic mcus. the mpasm assembler generates relocatable object files for the mplink object linker, intel ? standard hex files, map files to detail memory usage and symbol reference, absolute lst files that contain source lines and generated machine code and coff files for debugging. the mpasm assembler features include: ? integration into mplab ide projects ? user-defined macros to streamline assembly code ? conditional assembly for multi-purpose source files ? directives that allow complete control over the assembly process 24.3 mplab c18 and mplab c30 c compilers the mplab c18 and mplab c30 code development systems are complete ansi c compilers for microchip?s pic18 and pic24 families of microcon- trollers and the dspic30 and dspic33 family of digital signal controllers. these compilers provide powerful integration capabilities, superior code optimization and ease of use not found with other compilers. for easy source level debugging, the compilers provide symbol information that is optimized to the mplab ide debugger. 24.4 mplink object linker/ mplib object librarian the mplink object linker combines relocatable objects created by the mpasm assembler and the mplab c18 c compiler. it can link relocatable objects from precompiled libraries, using directives from a linker script. the mplib object librarian manages the creation and modification of library files of precompiled code. when a routine from a library is called from a source file, only the modules that contain that routine will be linked in with the application. this allows large libraries to be used efficiently in many different applications. the object linker/library features include: ? efficient linking of single libraries instead of many smaller files ? enhanced code maintainability by grouping related modules together ? flexible creation of libraries with easy module listing, replacement, deletion and extraction 24.5 mplab asm30 assembler, linker and librarian mplab asm30 assembler produces relocatable machine code from symbolic assembly language for dspic30f devices. mplab c30 c compiler uses the assembler to produce its object file. the assembler generates relocatable object files that can then be archived or linked with other relocatable object files and archives to create an executable file. notable features of the assembler include: ? support for the entire dspic30f instruction set ? support for fixed-point and floating-point data ? command line interface ? rich directive set ? flexible macro language ? mplab ide compatibility 24.6 mplab sim software simulator the mplab sim software simulator allows code development in a pc-hosted environment by simulat- ing the pic mcus and dspic ? dscs on an instruction level. on any given instruction, the data areas can be examined or modified and stimuli can be applied from a comprehensive stimulus controller. registers can be logged to files for further run-time analysis. the trace buffer and logic analyzer display extend the power of the simulator to record and track program execution, actions on i/o, most peripherals and internal registers. the mplab sim software simulator fully supports symbolic debugging using the mplab c18 and mplab c30 c compilers, and the mpasm and mplab asm30 assemblers. the software simulator offers the flexibility to develop and debug code outside of the hardware laboratory environment, making it an excellent, economical software development tool.
? 2009 microchip technology inc. preliminary ds39937b-page 175 pic24f04ka201 family 24.7 mplab ice 2000 high-performance in-circuit emulator the mplab ice 2000 in-circuit emulator is intended to provide the product development engineer with a complete microcontroller design tool set for pic microcontrollers. software control of the mplab ice 2000 in-circuit emulator is advanced by the mplab integrated development environment, which allows editing, building, downloading and source debugging from a single environment. the mplab ice 2000 is a full-featured emulator system with enhanced trace, trigger and data monitor- ing features. interchangeable processor modules allow the system to be easily reconfigured for emulation of different processors. the architecture of the mplab ice 2000 in-circuit emulator allows expansion to support new pic microcontrollers. the mplab ice 2000 in-circuit emulator system has been designed as a real-time emulation system with advanced features that are typically found on more expensive development tools. the pc platform and microsoft ? windows ? 32-bit operating system were chosen to best make these features available in a simple, unified application. 24.8 mplab real ice in-circuit emulator system mplab real ice in-circuit emulator system is microchip?s next generation high-speed emulator for microchip flash dsc and mcu devices. it debugs and programs pic ? flash mcus and dspic ? flash dscs with the easy-to-use, powerful graphical user interface of the mplab integrated development environment (ide), included with each kit. the mplab real ice probe is connected to the design engineer?s pc using a high-speed usb 2.0 interface and is connected to the target with either a connector compatible with the popular mplab icd 2 system (rj11) or with the new high-speed, noise tolerant, low- voltage differential signal (lvds) interconnection (cat5). mplab real ice is field upgradeable through future firmware downloads in mplab ide. in upcoming releases of mplab ide, new devices will be supported, and new features will be added, such as software break- points and assembly code trace. mplab real ice offers significant advantages over competitive emulators including low-cost, full-speed emulation, real-time variable watches, trace analysis, complex breakpoints, a ruggedized probe interface and long (up to three meters) interconnection cables. 24.9 mplab icd 2 in-circuit debugger microchip?s in-circuit debugger, mplab icd 2, is a powerful, low-cost, run-time development tool, connecting to the host pc via an rs-232 or high-speed usb interface. this tool is based on the flash pic mcus and can be used to develop for these and other pic mcus and dspic dscs. the mplab icd 2 utilizes the in-circuit debugging capability built into the flash devices. this feature, along with microchip?s in-circuit serial programming tm (icsp tm ) protocol, offers cost- effective, in-circuit flash debugging from the graphical user interface of the mplab integrated development environment. this enables a designer to develop and debug source code by setting breakpoints, single step- ping and watching variables, and cpu status and peripheral registers. running at full speed enables testing hardware and applications in real time. mplab icd 2 also serves as a development programmer for selected pic devices. 24.10 mplab pm3 device programmer the mplab pm3 device programmer is a universal, ce compliant device programmer with programmable voltage verification at v ddmin and v ddmax for maximum reliability. it features a large lcd display (128 x 64) for menus and error messages and a modu- lar, detachable socket assembly to support various package types. the icsp? cable assembly is included as a standard item. in stand-alone mode, the mplab pm3 device programmer can read, verify and program pic devices without a pc connection. it can also set code protection in this mode. the mplab pm3 connects to the host pc via an rs-232 or usb cable. the mplab pm3 has high-speed communications and optimized algorithms for quick programming of large memory devices and incorporates an sd/mmc card for file storage and secure data applications.
pic24f04ka201 family ds39937b-page 176 preliminary ? 2009 microchip technology inc. 24.11 picstart plus development programmer the picstart plus development programmer is an easy-to-use, low-cost, prototype programmer. it connects to the pc via a com (rs-232) port. mplab integrated development environment software makes using the programmer simple and efficient. the picstart plus development programmer supports most pic devices in dip packages up to 40 pins. larger pin count devices, such as the pic16c92x and pic17c76x, may be supported with an adapter socket. the picstart plus development programmer is ce compliant. 24.12 pickit 2 development programmer the pickit? 2 development programmer is a low-cost programmer and selected flash device debugger with an easy-to-use interface for programming many of microchip?s baseline, mid-range and pic18f families of flash memory microcontrollers. the pickit 2 starter kit includes a prototyping development board, twelve sequential lessons, software and hi-tech?s picc? lite c compiler, and is designed to help get up to speed quickly using pic ? microcontrollers. the kit provides everything needed to program, evaluate and develop applications using microchip?s powerful, mid-range flash memory family of microcontrollers. 24.13 demonstration, development and evaluation boards a wide variety of demonstration, development and evaluation boards for various pic mcus and dspic dscs allows quick application development on fully func- tional systems. most boards include prototyping areas for adding custom circuitry and provide application firmware and source code for examination and modification. the boards support a variety of features, including leds, temperature sensors, switches, speakers, rs-232 interfaces, lcd displays, potentiometers and additional eeprom memory. the demonstration and development boards can be used in teaching environments, for prototyping custom circuits and for learning about various microcontroller applications. in addition to the picdem? and dspicdem? demon- stration/development board series of circuits, microchip has a line of evaluation kits and demonstration software for analog filter design, k ee l oq ? security ics, can, irda ? , powersmart battery management, seeval ? evaluation system, sigma-delta adc, flow rate sensing, plus many more. check the microchip web page (www.microchip.com) for the complete list of demonstration, development and evaluation kits.
? 2009 microchip technology inc. preliminary ds39937b-page 177 pic24f04ka201 family 25.0 instruction set summary the pic24f instruction set adds many enhancements to the previous pic ? mcu instruction sets, while maintaining an easy migration from previous pic mcu instruction sets. most instructions are a single program memory word. only three instructions require two program memory locations. each single-word instruction is a 24-bit word divided into an 8-bit opcode, which specifies the instruction type and one or more operands, which further specify the operation of the instruction. the instruction set is highly orthogonal and is grouped into four basic categories: ? word or byte-oriented operations ? bit-oriented operations ? literal operations ? control operations table 25-1 lists the general symbols used in describing the instructions. the pic24f instruction set summary in table 25-2 lists all the instructions, along with the status flags affected by each instruction. most word or byte-oriented w register instructions (including barrel shift instructions) have three operands: ? the first source operand, which is typically a register ?wb? without any address modifier ? the second source operand, which is typically a register ?ws? with or without an address modifier ? the destination of the result, which is typically a register ?wd? with or without an address modifier however, word or byte-oriented file register instructions have two operands: ? the file register specified by the value, ?f? ? the destination, which could either be the file register, ?f?, or the w0 register, which is denoted as ?wreg? most bit-oriented instructions (including simple rotate/shift instructions) have two operands: ? the w register (with or without an address modifier) or file register (specified by the value of ?ws? or ?f?) ? the bit in the w register or file register (specified by a literal value or indirectly by the contents of register ?wb?) the literal instructions that involve data movement may use some of the following operands: ? a literal value to be loaded into a w register or file register (specified by the value of ?k?) ? the w register or file register where the literal value is to be loaded (specified by ?wb? or ?f?) however, literal instructions that involve arithmetic or logical operations use some of the following operands: ? the first source operand, which is a register ?wb? without any address modifier ? the second source operand, which is a literal value ? the destination of the result (only if not the same as the first source operand), which is typically a register ?wd? with or without an address modifier the control instructions may use some of the following operands: ? a program memory address ? the mode of the table read and table write instructions all instructions are a single word, except for certain double-word instructions, which were made double-word instructions so that all of the required information is available in these 48 bits. in the second word, the 8 msbs are ? 0 ?s. if this second word is executed as an instruction (by itself), it will execute as a nop . most single-word instructions are executed in a single instruction cycle, unless a conditional test is true or the program counter (pc) is changed as a result of the instruction. in these cases, the execution takes two instruction cycles, with the additional instruction cycle(s) executed as a nop . notable exceptions are the bra (unconditional/computed branch), indirect call/goto , all table reads and writes, and return/retfie instructions, which are single-word instructions but take two or three cycles. certain instructions that involve skipping over the subsequent instruction require either two or three cycles if the skip is performed, depending on whether the instruction being skipped is a single-word or two-word instruction. moreover, double-word moves require two cycles. the double-word instructions execute in two instruction cycles. note: this chapter is a brief summary of the pic24f instruction set architecture and is not intended to be a comprehensive reference source.
pic24f04ka201 family ds39937b-page 178 preliminary ? 2009 microchip technology inc. table 25-1: symbols used in opcode descriptions field description #text means literal defined by ? text ? (text) means ?content of text ? [text] means ?the location addressed by text ? { } optional field or operation register bit field .b byte mode selection .d double-word mode selection .s shadow register select .w word mode selection (default) bit4 4-bit bit selection field (used in word addressed instructions) {0...15} c, dc, n, ov, z mcu status bits: carry, digit carry, negative, overflow, sticky zero expr absolute address, label or expression (resolved by the linker) f file register address {0000h...1fffh} lit1 1-bit unsigned literal {0,1} lit4 4-bit unsigned literal {0...15} lit5 5-bit unsigned literal {0...31} lit8 8-bit unsigned literal {0...255} lit10 10-bit unsigned literal {0...255} for byte mode, {0:1023} for word mode lit14 14-bit unsigned literal {0...16384} lit16 16-bit unsigned literal {0...65535} lit23 23-bit unsigned literal {0...8388608}; lsb must be ? 0 ? none field does not require an entry, may be blank pc program counter slit10 10-bit signed literal {-512...511} slit16 16-bit signed literal {-32768...32767} slit6 6-bit signed literal {-16...16} wb base w register {w0..w15} wd destination w register { wd, [wd], [wd++], [wd--], [++wd], [--wd] } wdo destination w register { wnd, [wnd], [wnd++], [wnd--], [++wnd], [--wnd], [wnd+wb] } wm,wn dividend, divisor working r egister pair (direct addressing) wn one of 16 working registers {w0..w15} wnd one of 16 destination working registers {w0..w15} wns one of 16 source working registers {w0..w15} wreg w0 (working register used in file register instructions) ws source w register { ws, [ws], [ws++], [ws--], [++ws], [--ws] } wso source w register { wns, [wns], [wns++], [wns--], [++wns], [--wns], [wns+wb] }
? 2009 microchip technology inc. preliminary ds39937b-page 179 pic24f04ka201 family table 25-2: instruction set overview assembly mnemonic assembly syntax description # of words # of cycles status flags affected add add f f = f + wreg 1 1 c, dc, n, ov, z add f,wreg wreg = f + wreg 1 1 c, dc, n, ov, z add #lit10,wn wd = lit10 + wd 1 1 c, dc, n, ov, z add wb,ws,wd wd = wb + ws 1 1 c, dc, n, ov, z add wb,#lit5,wd wd = wb + lit5 1 1 c, dc, n, ov, z addc addc f f = f + wreg + (c) 1 1 c, dc, n, ov, z addc f,wreg wreg = f + wreg + (c) 1 1 c, dc, n, ov, z addc #lit10,wn wd = lit10 + wd + (c) 1 1 c, dc, n, ov, z addc wb,ws,wd wd = wb + ws + (c) 1 1 c, dc, n, ov, z addc wb,#lit5,wd wd = wb + lit5 + (c) 1 1 c, dc, n, ov, z and and f f = f .and. wreg 1 1 n, z and f,wreg wreg = f .and. wreg 1 1 n, z and #lit10,wn wd = lit10 .and. wd 1 1 n, z and wb,ws,wd wd = wb .and. ws 1 1 n, z and wb,#lit5,wd wd = wb .and. lit5 1 1 n, z asr asr f f = arithmetic right shift f 1 1 c, n, ov, z asr f,wreg wreg = arithmetic right shift f 1 1 c, n, ov, z asr ws,wd wd = arithmetic right shift ws 1 1 c, n, ov, z asr wb,wns,wnd wnd = arithmetic right shift wb by wns 1 1 n, z asr wb,#lit5,wnd wnd = arithmetic right shift wb by lit5 1 1 n, z bclr bclr f,#bit4 bit clear f 1 1 none bclr ws,#bit4 bit clear ws 1 1 none bra bra c,expr branch if carry 1 1 (2) none bra ge,expr branch if greater than or equal 1 1 (2) none bra geu,expr branch if unsigned greater than or equal 1 1 (2) none bra gt,expr branch if greater than 1 1 (2) none bra gtu,expr branch if unsigned greater than 1 1 (2) none bra le,expr branch if less than or equal 1 1 (2) none bra leu,expr branch if unsigned less than or equal 1 1 (2) none bra lt,expr branch if less than 1 1 (2) none bra ltu,expr branch if unsigned less than 1 1 (2) none bra n,expr branch if negative 1 1 (2) none bra nc,expr branch if not carry 1 1 (2) none bra nn,expr branch if not negative 1 1 (2) none bra nov,expr branch if not overflow 1 1 (2) none bra nz,expr branch if not zero 1 1 (2) none bra ov,expr branch if overflow 1 1 (2) none bra expr branch unconditionally 1 2 none bra z,expr branch if zero 1 1 (2) none bra wn computed branch 1 2 none bset bset f,#bit4 bit set f 1 1 none bset ws,#bit4 bit set ws 1 1 none bsw bsw.c ws,wb write c bit to ws 1 1 none bsw.z ws,wb write z bit to ws 1 1 none btg btg f,#bit4 bit toggle f 1 1 none btg ws,#bit4 bit toggle ws 1 1 none btsc btsc f,#bit4 bit test f, skip if clear 1 1 (2 or 3) none btsc ws,#bit4 bit test ws, skip if clear 1 1 (2 or 3) none
pic24f04ka201 family ds39937b-page 180 preliminary ? 2009 microchip technology inc. btss btss f,#bit4 bit test f, skip if set 1 1 (2 or 3) none btss ws,#bit4 bit test ws, skip if set 1 1 (2 or 3) none btst btst f,#bit4 bit test f 1 1 z btst.c ws,#bit4 bit test ws to c 1 1 c btst.z ws,#bit4 bit test ws to z 1 1 z btst.c ws,wb bit test ws to c 1 1 c btst.z ws,wb bit test ws to z 1 1 z btsts btsts f,#bit4 bit test then set f 1 1 z btsts.c ws,#bit4 bit test ws to c, then set 1 1 c btsts.z ws,#bit4 bit test ws to z, then set 1 1 z call call lit23 call subroutine 2 2 none call wn call indirect subroutine 1 2 none clr clr f f = 0x0000 1 1 none clr wreg wreg = 0x0000 1 1 none clr ws ws = 0x0000 1 1 none clrwdt clrwdt clear watchdog timer 1 1 wdto, sleep com com f f = f 11n, z com f,wreg wreg = f 11n, z com ws,wd wd = ws 11n, z cp cp f compare f with wreg 1 1 c, dc, n, ov, z cp wb,#lit5 compare wb with lit5 1 1 c, dc, n, ov, z cp wb,ws compare wb with ws (wb ? ws) 1 1 c, dc, n, ov, z cp0 cp0 f compare f with 0x0000 1 1 c, dc, n, ov, z cp0 ws compare ws with 0x0000 1 1 c, dc, n, ov, z cpb cpb f compare f with wreg, with borrow 1 1 c, dc, n, ov, z cpb wb,#lit5 compare wb with lit5, with borrow 1 1 c, dc, n, ov, z cpb wb,ws compare wb with ws, with borrow (wb ? ws ? c ) 1 1 c, dc, n, ov, z cpseq cpseq wb,wn compare wb with wn, skip if = 1 1 (2 or 3) none cpsgt cpsgt wb,wn compare wb with wn, skip if > 1 1 (2 or 3) none cpslt cpslt wb,wn compare wb with wn, skip if < 1 1 (2 or 3) none cpsne cpsne wb,wn compare wb with wn, skip if 11 (2 or 3) none daw daw wn wn = decimal adjust wn 1 1 c dec dec f f = f ?1 1 1 c, dc, n, ov, z dec f,wreg wreg = f ?1 1 1 c, dc, n, ov, z dec ws,wd wd = ws ? 1 1 1 c, dc, n, ov, z dec2 dec2 f f = f ? 2 1 1 c, dc, n, ov, z dec2 f,wreg wreg = f ? 2 1 1 c, dc, n, ov, z dec2 ws,wd wd = ws ? 2 1 1 c, dc, n, ov, z disi disi #lit14 disable interrupts for k instruction cycles 1 1 none div div.sw wm,wn signed 16/16-bit integer divide 1 18 n, z, c, ov div.sd wm,wn signed 32/16-bit integer divide 1 18 n, z, c, ov div.uw wm,wn unsigned 16/16-bit integer divide 1 18 n, z, c, ov div.ud wm,wn unsigned 32/16-bit integer divide 1 18 n, z, c, ov exch exch wns,wnd swap wns with wnd 1 1 none ff1l ff1l ws,wnd find first one from left (msb) side 1 1 c ff1r ff1r ws,wnd find first one from right (lsb) side 1 1 c table 25-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
? 2009 microchip technology inc. preliminary ds39937b-page 181 pic24f04ka201 family goto goto expr go to address 2 2 none goto wn go to indirect 1 2 none inc inc f f = f + 1 1 1 c, dc, n, ov, z inc f,wreg wreg = f + 1 1 1 c, dc, n, ov, z inc ws,wd wd = ws + 1 1 1 c, dc, n, ov, z inc2 inc2 f f = f + 2 1 1 c, dc, n, ov, z inc2 f,wreg wreg = f + 2 1 1 c, dc, n, ov, z inc2 ws,wd wd = ws + 2 1 1 c, dc, n, ov, z ior ior f f = f .ior. wreg 1 1 n, z ior f,wreg wreg = f .ior. wreg 1 1 n, z ior #lit10,wn wd = lit10 .ior. wd 1 1 n, z ior wb,ws,wd wd = wb .ior. ws 1 1 n, z ior wb,#lit5,wd wd = wb .ior. lit5 1 1 n, z lnk lnk #lit14 link frame pointer 1 1 none lsr lsr f f = logical right shift f 1 1 c, n, ov, z lsr f,wreg wreg = logical right shift f 1 1 c, n, ov, z lsr ws,wd wd = logical right shift ws 1 1 c, n, ov, z lsr wb,wns,wnd wnd = logical right shift wb by wns 1 1 n, z lsr wb,#lit5,wnd wnd = logical right shift wb by lit5 1 1 n, z mov mov f,wn move f to wn 1 1 none mov [wns+slit10],wnd move [wns+slit10] to wnd 1 1 none mov f move f to f 1 1 n, z mov f,wreg move f to wreg 1 1 n, z mov #lit16,wn move 16-bit literal to wn 1 1 none mov.b #lit8,wn move 8-bit literal to wn 1 1 none mov wn,f move wn to f 1 1 none mov wns,[wns+slit10] move wns to [wns+slit10] 1 1 none mov wso,wdo move ws to wd 1 1 none mov wreg,f move wreg to f 1 1 n, z mov.d wns,wd move double from w(ns):w(ns+1) to wd 1 2 none mov.d ws,wnd move double from ws to w(nd+1):w(nd) 1 2 none mul mul.ss wb,ws,wnd {wnd+1, wnd} = signed(wb) * signed(ws) 1 1 none mul.su wb,ws,wnd {wnd+1, wnd} = signed(wb) * unsigned(ws) 1 1 none mul.us wb,ws,wnd {wnd+1, wnd} = unsigned(wb) * signed(ws) 1 1 none mul.uu wb,ws,wnd {wnd+1, wnd} = unsigned(wb) * unsigned(ws) 1 1 none mul.su wb,#lit5,wnd {wnd+1, wnd} = signed(wb) * unsigned(lit5) 1 1 none mul.uu wb,#lit5,wnd {wnd+1, wnd} = unsigned(wb) * unsigned(lit5) 1 1 none mul f w3:w2 = f * wreg 1 1 none neg neg f f = f + 1 1 1 c, dc, n, ov, z neg f,wreg wreg = f + 1 1 1 c, dc, n, ov, z neg ws,wd wd = ws + 1 1 1 c, dc, n, ov, z nop nop no operation 1 1 none nopr no operation 1 1 none pop pop f pop f from top-of-stack (tos) 1 1 none pop wdo pop from top-of-stack (tos) to wdo 1 1 none pop.d wnd pop from top-of-stack (tos) to w(nd):w(nd+1) 1 2 none pop.s pop shadow registers 1 1 all push push f push f to top-of-stack (tos) 1 1 none push wso push wso to top-of-stack (tos) 1 1 none push.d wns push w(ns):w(ns+1) to top-of-stack (tos) 1 2 none push.s push shadow registers 1 1 none table 25-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
pic24f04ka201 family ds39937b-page 182 preliminary ? 2009 microchip technology inc. pwrsav pwrsav #lit1 go into sleep or idle mode 1 1 wdto, sleep rcall rcall expr relative call 1 2 none rcall wn computed call 1 2 none repeat repeat #lit14 repeat next instruction lit14 + 1 times 1 1 none repeat wn repeat next instruction (wn) + 1 times 1 1 none reset reset software device reset 1 1 none retfie retfie return from interrupt 1 3 (2) none retlw retlw #lit10,wn return with literal in wn 1 3 (2) none return return return from subroutine 1 3 (2) none rlc rlc f f = rotate left through carry f 1 1 c, n, z rlc f,wreg wreg = rotate left through carry f 1 1 c, n, z rlc ws,wd wd = rotate left through carry ws 1 1 c, n, z rlnc rlnc f f = rotate left (no carry) f 1 1 n, z rlnc f,wreg wreg = rotate left (no carry) f 1 1 n, z rlnc ws,wd wd = rotate left (no carry) ws 1 1 n, z rrc rrc f f = rotate right through carry f 1 1 c, n, z rrc f,wreg wreg = rotate right through carry f 1 1 c, n, z rrc ws,wd wd = rotate right through carry ws 1 1 c, n, z rrnc rrnc f f = rotate right (no carry) f 1 1 n, z rrnc f,wreg wreg = rotate right (no carry) f 1 1 n, z rrnc ws,wd wd = rotate right (no carry) ws 1 1 n, z se se ws,wnd wnd = sign-extended ws 1 1 c, n, z setm setm f f = ffffh 1 1 none setm wreg wreg = ffffh 1 1 none setm ws ws = ffffh 1 1 none sl sl f f = left shift f 1 1 c, n, ov, z sl f,wreg wreg = left shift f 1 1 c, n, ov, z sl ws,wd wd = left shift ws 1 1 c, n, ov, z sl wb,wns,wnd wnd = left shift wb by wns 1 1 n, z sl wb,#lit5,wnd wnd = left shift wb by lit5 1 1 n, z sub sub f f = f ? wreg 1 1 c, dc, n, ov, z sub f,wreg wreg = f ? wreg 1 1 c, dc, n, ov, z sub #lit10,wn wn = wn ? lit10 1 1 c, dc, n, ov, z sub wb,ws,wd wd = wb ? ws 1 1 c, dc, n, ov, z sub wb,#lit5,wd wd = wb ? lit5 1 1 c, dc, n, ov, z subb subb f f = f ? wreg ? (c ) 1 1 c, dc, n, ov, z subb f,wreg wreg = f ? wreg ? (c ) 1 1 c, dc, n, ov, z subb #lit10,wn wn = wn ? lit10 ? (c ) 1 1 c, dc, n, ov, z subb wb,ws,wd wd = wb ? ws ? (c ) 1 1 c, dc, n, ov, z subb wb,#lit5,wd wd = wb ? lit5 ? (c ) 1 1 c, dc, n, ov, z subr subr f f = wreg ? f 1 1 c, dc, n, ov, z subr f,wreg wreg = wreg ? f 1 1 c, dc, n, ov, z subr wb,ws,wd wd = ws ? wb 1 1 c, dc, n, ov, z subr wb,#lit5,wd wd = lit5 ? wb 1 1 c, dc, n, ov, z subbr subbr f f = wreg ? f ? (c ) 1 1 c, dc, n, ov, z subbr f,wreg wreg = wreg ? f ? (c ) 1 1 c, dc, n, ov, z subbr wb,ws,wd wd = ws ? wb ? (c ) 1 1 c, dc, n, ov, z subbr wb,#lit5,wd wd = lit5 ? wb ? (c ) 1 1 c, dc, n, ov, z swap swap.b wn wn = nibble swap wn 1 1 none swap wn wn = byte swap wn 1 1 none tblrdh tblrdh ws,wd read prog<23:16> to wd<7:0> 1 2 none table 25-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
? 2009 microchip technology inc. preliminary ds39937b-page 183 pic24f04ka201 family tblrdl tblrdl ws,wd read prog<15:0> to wd 1 2 none tblwth tblwth ws,wd write ws<7:0> to prog<23:16> 1 2 none tblwtl tblwtl ws,wd write ws to prog<15:0> 1 2 none ulnk ulnk unlink frame pointer 1 1 none xor xor f f = f .xor. wreg 1 1 n, z xor f,wreg wreg = f .xor. wreg 1 1 n, z xor #lit10,wn wd = lit10 .xor. wd 1 1 n, z xor wb,ws,wd wd = wb .xor. ws 1 1 n, z xor wb,#lit5,wd wd = wb .xor. lit5 1 1 n, z ze ze ws,wnd wnd = zero-extend ws 1 1 c, z, n table 25-2: instruction set overview (continued) assembly mnemonic assembly syntax description # of words # of cycles status flags affected
pic24f04ka201 family ds39937b-page 184 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 185 pic24f04ka201 family 26.0 electrical characteristics this section provides an overview of the pic24f04ka201 family electrical characteristics. additional information will be provided in future revisions of this document as it becomes available. absolute maximum ratings for the pic24f04ka201 family are listed below. exposure to these maximum rating conditions for extended periods may affect device reliability. functional operation of the device at these, or any other conditions above the parameters indicated in the operation listings of this specification, is not implied. absolute maximum ratings (?) ambient temperature under bias................................................................................................. ............-40c to +125c storage temperature ............................................................................................................ .................. -65c to +150c voltage on v dd with respect to v ss ......................................................................................................... -0.3v to +5.0v voltage on any combined analog and digital pin, with respect to v ss ........................................... -0.3v to (v dd + 0.3v) voltage on any digital only pin with respect to v ss ....................................................................... -0.3v to (v dd + 0.3v) voltage on mclr /v pp pin with respect to v ss ......................................................................................... -0.3v to +9.0v maximum current out of v ss pin ........................................................................................................................... 300 ma maximum current into v dd pin (1) ..........................................................................................................................250 m a maximum output current sunk by any i/o pin..................................................................................... .....................25 ma maximum output current sourced by any i/o pin .................................................................................. ..................25 ma maximum current sunk by all ports .............................................................................................. .........................200 ma maximum current sourced by all ports (1) ..............................................................................................................200 ma note 1: maximum allowable current is a function of device maximum power dissipation (see table 26-1). ?notice: stresses above those listed under ?absolute maximum ratings? may cause permanent damage to the device. this is a stress rating only and functional operation of the device at those or any other conditions above those indicated in the operation listings of this specification is not implied. exposure to maximum rating conditions for extended periods may affect device reliability.
pic24f04ka201 family ds39937b-page 186 preliminary ? 2009 microchip technology inc. 26.1 dc characteristics figure 26-1: pic24f04ka201 family vo ltage-frequency graph (industrial) table 26-1: thermal operating conditions rating symbol min typ max unit operating junction temperature range t j -40 ? +125 c operating ambient temperature range t a -40 ? +85 c power dissipation: internal chip power dissipation: p int = v dd x (i dd ? i oh ) p d p int + p i / o w i/o pin power dissipation: p i / o = ({v dd ? v oh } x i oh ) + (v ol x i ol ) maximum allowed power dissipation p dmax (t j ? t a )/ ja w frequency voltage (v dd ) 1.80v 32 mhz 3.60v 3.00v 3.60v 8 mhz 3.00v note: for frequencies between 8 mhz and 32 mhz, f max = 20 mhz *(v dd ? 1.8) + 8 mhz. table 26-2: thermal packaging characteristics characteristic symbol typ max unit notes package thermal resistance, 14-pin pdip ja 62.4 ? c/w 1 package thermal resistance, 20-pin pdip ja 60 ? c/w 1 package thermal resistance, 14-pin ssop ja 108 ? c/w 1 package thermal resistance, 20-pin ssop ja 71 ? c/w 1 package thermal resistance, 14-pin soic ja 75 ? c/w 1 package thermal resistance, 20-pin soic ja 80.2 ? c/w 1 package thermal resistance, 14-pin qfn ja 43 ? c/w 1 package thermal resistance, 20-pin qfn ja 32 ? c/w 1 note 1: junction to ambient thermal resistance, theta- ja ( ja ) numbers are achieved by package simulations.
? 2009 microchip technology inc. preliminary ds39937b-page 187 pic24f04ka201 family table 26-4: high/low?voltage detect characteristics table 26-3: dc characteristics: temperature and voltage specifications dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min typ (1) max units conditions dc10 v dd supply voltage 1.8 ? 3.6 v dc12 v dr ram data retention voltage (2) 1.5 ? ? v dc16 v por v dd start voltage to ensure internal power-on reset signal v ss ?0.7v dc17 s vdd v dd rise rate to ensure internal power-on reset signal 0.05 ? ? v/ms 0-3.3v in 0.1s 0-2.5v in 60 ms note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: this is the limit to which v dd can be lowered without losing ram data. standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min typ max units conditions dc18 v hlvd hlvd voltage on v dd transition hlvdl<3:0> = 0000 ? 1.85 1.94 v hlvdl<3:0> = 0001 1.81 1.90 2.00 v hlvdl<3:0> = 0010 1.85 1.95 2.05 v hlvdl<3:0> = 0011 1.90 2.00 2.10 v hlvdl<3:0> = 0100 1.95 2.05 2.15 v hlvdl<3:0> = 0101 2.06 2.17 2.28 v hlvdl<3:0> = 0110 2.12 2.23 2.34 v hlvdl<3:0> = 0111 2.24 2.36 2.48 v hlvdl<3:0> = 1000 2.31 2.43 2.55 v hlvdl<3:0> = 1001 2.47 2.60 2.73 v hlvdl<3:0> = 1010 2.64 2.78 2.92 v hlvdl<3:0> = 1011 2.74 2.88 3.02 v hlvdl<3:0> = 1100 2.85 3.00 3.15 v hlvdl<3:0> = 1101 2.96 3.12 3.28 v hlvdl<3:0> = 1110 3.22 3.39 3.56 v
pic24f04ka201 family ds39937b-page 188 preliminary ? 2009 microchip technology inc. table 26-5: bor trip points standard operating conditions (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ max units conditions dc19 bor voltage on v dd transition bor = 00 1.55 2 2.00 v valid for lpbor and dsbor bor = 01 2.92 3 3.25 v bor = 10 2.63 2.7 2.92 v bor = 11 1.75 1.78 2.01 v table 26-6: dc characteristics: operating current (i dd ) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial parameter no. typical (1) max units conditions i dd current dc20 195 330 a -40c 1.8v 0.5 mips, f osc = 1 mhz ds20a 330 +25c dc20b 330 +60c dc20c 330 +85c dc20d 365 590 a -40c 3.3v dc20e 590 +25c dc20f 645 +60c dc20g 720 +85c dc22 363 600 a -40c 1.8v 1 mips, f osc = 2 mhz dc22a 600 +25c dc22b 600 +60c dc22c 600 +85c dc22d 695 1100 a -40c 3.3v dc22e 1100 +25c dc22f 1100 +60c dc22g 1100 +85c dc23 11 18 ma -40c 3.3v 16 mips, f osc = 32 mhz dc23a 18 +25c dc23b 18 +60c dc23c 18 +85c dc27 2.25 3.40 ma -40c 2.5v frc (4 mips), f osc = 8 mhz dc27a 3.40 +25c dc27b 3.40 +60c dc27c 3.40 +85c dc27d 3.05 4.60 ma -40c 3.3v dc27e 4.60 +25c dc27f 4.60 +60c dc27g 4.60 +85c note 1: data in ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: operating parameters: ? ec mode with clock input driven with a square wave rail-to-rail ? i/o configured as outputs driven low ? mclr ? v dd ? wdt fscm disabled ? sram, program and data memory active ? all pmd bits set except for modules being measured
? 2009 microchip technology inc. preliminary ds39937b-page 189 pic24f04ka201 family dc31 8 28 a -40c 1.8v lprc (31 khz) dc31a 28 +25c dc31b 28 +60c dc31c 28 +85c dc31d 15 55 a -40c 3.3v dc31e 55 +25c dc31f 55 +60c dc31g 55 +85c table 26-7: dc characteristics: idle current (i idle ) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. typical (1) max units conditions idle current (i idle ): core off, clock on base current, pmd bits are set (2) dc40 48 100 a -40c 1.8v 0.5 mips, f osc = 1 mhz dc40a 100 +25c dc40b 100 +60c dc40c 100 +85c dc40d 106 215 a -40c 3.3v dc40e 215 +25c dc40f 215 +60c dc40g 215 +85c note 1: data in ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: operating parameters: ? core off ? ec mode with clock input driven with a square wave rail-to-rail ? i/o configured as outputs driven low ? mclr ? v dd ? wdt fscm disabled ? sram, program and data memory active ? all pmd bits set except for modules being measured table 26-6: dc characteristics: operating current (i dd ) (continued) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial parameter no. typical (1) max units conditions i dd current note 1: data in ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: operating parameters: ? ec mode with clock input driven with a square wave rail-to-rail ? i/o configured as outputs driven low ? mclr ? v dd ? wdt fscm disabled ? sram, program and data memory active ? all pmd bits set except for modules being measured
pic24f04ka201 family ds39937b-page 190 preliminary ? 2009 microchip technology inc. dc42 94 200 a -40c 1.8v 1 mips, f osc = 2 mhz dc42a 200 +25c dc42b 200 +60c dc42c 200 +85c dc42d 160 395 a -40c 3.3v dc42e 395 +25c dc42f 395 +60c dc42g 395 +85c dc43 3.1 6.0 ma -40c 3.3v 16 mips, f osc = 32 mhz dc43a 6.0 +25c dc43b 6.0 +60c dc43c 6.0 +85c dc44 0.56 0.74 ma -40c 1.8v frc (4 mips), f osc = 8 mhz dc44a 0.74 +25c dc44b 0.74 +60c dc44c 0.74 +85c dc44d 0.95 1.50 ma -40c 3.3v dc44e 1.50 +25c dc44f 1.50 +60c dc44g 1.50 +85c dc50 2 18 a -40c 1.8v lprc (31 khz) dc50a 18 +25c dc50b 18 +60c dc50c 18 +85c dc50d 4 40 a -40c 3.3v dc50e 40 +25c dc50f 40 +60c dc50g 40 +85c table 26-7: dc characteristics: idle current (i idle ) (continued) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. typical (1) max units conditions idle current (i idle ): core off, clock on base current, pmd bits are set (2) note 1: data in ?typical? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: operating parameters: ? core off ? ec mode with clock input driven with a square wave rail-to-rail ? i/o configured as outputs driven low ? mclr ? v dd ? wdt fscm disabled ? sram, program and data memory active ? all pmd bits set except for modules being measured
? 2009 microchip technology inc. preliminary ds39937b-page 191 pic24f04ka201 family table 26-8: dc characteristics: power-down current (i pd ) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial parameter no. typical (1) max units conditions power-down current (i pd ): pmd bits are set, pmslp bit is ? 0 ? (2) dc60 0.025 0.200 a -40c 1.8v base power-down current (sleep) (3) dc60a 0.200 +25c dc60b 0.870 +60c dc60c 1.350 +85c dc60d 0.105 0.540 a -40c 3.3v dc60e 0.540 +25c dc60f 1.680 +60c dc60g 2.450 +85c dc70 0.020 0.150 a -40c 1.8v base deep sleep current dc70a 0.150 +25c dc70b 0.430 +60c dc70c 0.630 +85c dc70d 0.035 0.300 a -40c 3.3v dc70e 0.300 +25c dc70f 0.700 +60c dc70g 0.980 +85c dc61 0.55 0.65 a -40c 1.8v watchdog timer current: wdt (3,4) dc61a 0.65 +25c dc61b 0.65 +60c dc61c 0.65 +85c dc61d 0.87 0.95 a -40c 3.3v dc61e 0.95 +25c dc61f 0.95 +60c dc61g 0.95 +85c note 1: data in the typical column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: base i pd is measured with all peripherals and clocks shut down. all i/os are configured as inputs and pulled high. wdt, etc., are all switched off. 3: the current is the additional current consumed when the module is enabled. this current should be added to the base i pd current. 4: current applies to sleep only. 5: current applies to deep sleep only.
pic24f04ka201 family ds39937b-page 192 preliminary ? 2009 microchip technology inc. dc62 0.450 0.650 a -40c 1.8v timer1 w/32 khz crystal: t132 (sosc ? lp) (3) dc62a 0.650 +25c dc62b 0.650 +60c dc62c 0.650 +85c dc62d 0.730 0.980 a -40c 3.3v dc62e 0.980 +25c dc62f 0.980 +60c dc62g 0.980 +85c dc64 5.5 7.10 a -40c 1.8v hlvd (3,4) dc64a 7.10 +25c dc64b 7.80 +60c dc64c 8.30 +85c dc64d 6.2 7.10 a -40c 3.3v dc64e 7.10 +25c dc64f 7.80 +60c dc64g 8.30 +85c dc63 4.5 6.60 a -40c 3.3v bor (3,4) dc63a 6.60 +25c dc63b 6.60 +60c dc63c 6.60 +85c table 26-8: dc characteristics: power-down current (i pd ) (continued) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial parameter no. typical (1) max units conditions power-down current (i pd ): pmd bits are set, pmslp bit is ? 0 ? (2) note 1: data in the typical column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: base i pd is measured with all peripherals and clocks shut down. all i/os are configured as inputs and pulled high. wdt, etc., are all switched off. 3: the current is the additional current consumed when the module is enabled. this current should be added to the base i pd current. 4: current applies to sleep only. 5: current applies to deep sleep only.
? 2009 microchip technology inc. preliminary ds39937b-page 193 pic24f04ka201 family dc70 0.045 0.200 a -40c 1.8v lpbor (3,4) dc70a 0.200 +25c dc70b 0.200 +60c dc70c 0.200 +85c dc70d 0.095 0.200 a -40c 3.3v dc70e 0.200 +25c dc70f 0.200 +60c dc70g 0.200 +85c dc71 0.35 0.55 a -40c 1.8v deep sleep watchdog timer: dswdt (sosc ? lp) (5) dc71a 0.55 +25c dc71b 0.55 +60c dc71c 0.55 +85c dc71d 0.55 0.75 a -40c 3.3v dc71e 0.75 +25c dc71f 0.75 +60c dc71g 0.75 +85c dc72 0.005 0.200 a -40c 1.8v deep sleep bor: dsbor (3,5) dc72a 0.200 +25c dc72b 0.200 +60c dc72c 0.200 +85c dc72d 0.010 0.200 a -40c 3.3v dc72e 0.200 +25c dc72f 0.200 +60c dc72g 0.200 +85c table 26-8: dc characteristics: power-down current (i pd ) (continued) dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial parameter no. typical (1) max units conditions power-down current (i pd ): pmd bits are set, pmslp bit is ? 0 ? (2) note 1: data in the typical column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: base i pd is measured with all peripherals and clocks shut down. all i/os are configured as inputs and pulled high. wdt, etc., are all switched off. 3: the current is the additional current consumed when the module is enabled. this current should be added to the base i pd current. 4: current applies to sleep only. 5: current applies to deep sleep only.
pic24f04ka201 family ds39937b-page 194 preliminary ? 2009 microchip technology inc. table 26-9: dc characteristics: i/o pin input specifications dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ (1) max units conditions v il input low voltage (4) ???? di10 i/o pins v ss ? 0.2 v dd v di15 mclr v ss ? 0.2 v dd v di16 osci (xt mode) v ss ? 0.2 v dd v di17 osci (hs mode) v ss ? 0.2 v dd v di18 i/o pins with i 2 c? buffer v ss ? 0.3 v dd v smbus disabled di19 i/o pins with smbus buffer v ss ? 0.8 v smbus enabled v ih input high voltage (4) ???? di20 i/o pins: with analog functions digital only 0.8 v dd 0.8 v dd ? ? v dd v dd v v di25 mclr 0.8 v dd ?v dd v di26 osci (xt mode) 0.7 v dd ?v dd v di27 osci (hs mode) 0.7 v dd ?v dd v di28 i/o pins with i 2 c buffer: with analog functions digital only 0.7 v dd 0.7 v dd ? ? v dd v dd v v di29 i/o pins with smbus 2.1 ? v dd v2.5v v pin v dd di30 i cnpu cnx pull-up current 50 250 500 av dd = 3.3v, v pin = v ss i il input leakage current (2,3) di50 i/o ports ? 0.050 0.100 av ss v pin v dd , pin at high-impedance di51 v ref +, v ref -, an0, an1 ? 0.300 0.500 av ss v pin v dd , pin at high-impedance di55 mclr ??5.0 av ss v pin v dd di56 osci ? ? 5.0 av ss v pin v dd , xt and hs modes note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: the leakage current on the mclr pin is strongly dependent on the applied voltage level. the specified levels represent normal operating conditions. higher leakage current may be measured at different input voltages. 3: negative current is defined as current sourced by the pin. 4: refer to table 1-2 for i/o pin buffer types.
? 2009 microchip technology inc. preliminary ds39937b-page 195 pic24f04ka201 family table 26-10: dc characteristics: i/o pin output specifications dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ (1) max units conditions v ol output low voltage do10 all i/o pins ? ? 0.4 v i ol = 6.5 ma, v dd = 3.6v ??0.4vi ol = 3.5 ma, v dd = 2.0v do16 osc2/clko ? ? 0.4 v i ol = 8.0 ma, v dd = 3.6v ??0.4vi ol = 4.5 ma, v dd = 1.8v v oh output high voltage ???? ? do20 all i/o pins 3 ? ? v i oh = -3.0 ma, v dd = 3.6v 1.8 ? ? v i oh = -1.0 ma, v dd = 2.0v do26 osc2/clko 3 ? ? v i oh = -2.5 ma, v dd = 3.6v 1.8 ? ? v i oh = -1.0 ma, v dd = 2.0v note 1: data in ?typ? column is at 25c unless otherwise stated. parameters are for design guidance only and are not tested. table 26-11: dc characteristics: program memory dc characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ (1) max units conditions program flash memory d130 e p cell endurance 10,000 (2) ??e/w d131 v pr v dd for read v min ?3.6vv min = minimum operating voltage d132 v pew supply voltage for self-timed writes 2.2 ? 3.6 v d133a t iw self-timed write cycle time ? 2 ? ms d134 t retd characteristic retention 40 ? ? year provided no other specifications are violated d135 i ddp supply current during programming ?10?ma note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. 2: self-write and block erase.
pic24f04ka201 family ds39937b-page 196 preliminary ? 2009 microchip technology inc. table 26-12: comparat or dc specifications table 26-13: comparator voltag e reference dc specifications table 26-15: comp arator timings table 26-16: comparator voltage re ference settling time specifications operating conditions: 2.0v < v dd < 3.6v, -40c < t a < +85c (unless otherwise stated) param no. symbol characteristic min typ max units comments d300 v ioff input offset voltage* ? 20 40 mv d301 v icm input common mode voltage* 0 ? v dd v d302 cmrr common mode rejection ratio* 55 ? ? db * parameters are characterized but not tested. operating conditions: 2.0v < v dd < 3.6v, -40c < t a < +85c (unless otherwise stated) param no. symbol characteristic min typ max units comments vrd310 cv res resolution v dd /24 ? v dd /32 lsb vrd311 cvr aa absolute accuracy ? ? av dd ? 1.5 lsb vrd312 cvr ur unit resistor value (r) ? 2k ? table 26-14: ctmu current source specifications dc characteristics standard operating conditions: 2.0v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ (1) max units conditions i out 1 ctmu current source, base range ? 550 ? na ctmuicon<1:0> = 01 i out 2 ctmu current source, 10x range ?5.5? a ctmuicon<1:0> = 10 i out 3 ctmu current source, 100x range ?55? a ctmuicon<1:0> = 11 note 1: nominal value at center point of current trim range (ctmuicon<7:2> = 000000 ) param no. symbol characteristic min typ max units comments 300 t resp response time* (1) ? 150 400 ns 301 t mc 2 ov comparator mode change to output valid * ?? 10 s * parameters are characterized but not tested. note 1: response time measured with one comparator input at (v dd ? 1.5)/2, while the other input transitions from v ss to v dd . param no. symbol characteristic min typ max units comments vr310 t set settling time (1) ??10 s note 1: settling time measured while cvrr = 1 and cvr<3:0> bits transition from ? 0000 ? to ? 1111 ?.
? 2009 microchip technology inc. preliminary ds39937b-page 197 pic24f04ka201 family 26.2 ac characteristics and timing parameters the information contained in this section defines the pic24f04ka201 family ac characteristics and timing parameters. table 26-17: temperature and vo ltage specifications ? ac figure 26-2: load conditions for device timing specifications table 26-18: capacitiv e loading requirements on output pins ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial operating voltage v dd range as described in section 26.1 ?dc characteristics? . param no. symbol characteristic min typ (1) max units conditions do50 c osc 2 osco/clko pin ? ? 15 pf in xt and hs modes when external clock is used to drive osci do56 c io all i/o pins and osco ? ? 50 pf ec mode do58 c b sclx, sdax ? ? 400 pf in i 2 c? mode note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. v dd /2 c l r l pin pin v ss v ss c l r l = 464 c l = 50 pf for all pins except osco 15 pf for osco output load condition 1 ? for all pins except osco load condition 2 ? for osco
pic24f04ka201 family ds39937b-page 198 preliminary ? 2009 microchip technology inc. figure 26-3: external clock timing osci clko q4 q1 q2 q3 q4 q1 os20 os25 os30 os30 os40 os41 os31 os31 q1 q2 q3 q4 q2 q3 table 26-19: external clo ck timing requirements ac characteristics standard operating conditions: 1.8 to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ (1) max units conditions os10 f osc external clki frequency (external clocks allowed only in ec mode) dc 4 ? ? 32 8 mhz mhz ec ecpll oscillator frequency 0.2 4 4 31 ? ? ? ? 4 25 8 33 mhz mhz mhz khz xt hs hspll sosc os20 t osc t osc = 1/f osc ? ? ? ? see parameter os10 for f osc value os25 t cy instruction cycle time (2) 62.5 ? dc ns os30 tosl, to s h external clock in (osci) high or low time 0.45 x t osc ??nsec os31 tosr, to s f external clock in (osci) rise or fall time ??20nsec os40 tckr clko rise time (3) ?610ns os41 tckf clko fall time (3) ?610ns note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. 2: instruction cycle period (t cy ) equals two times the input oscillator time base period. all specified values are based on characterization data for that particular oscillator type under standard operating conditions with the device executing code. exceeding these specified limits may result in an unstable oscillator operation and/or higher than expected current consumption. all devices are tested to operate at ?min.? values with an external clock applied to the osci/clki pin. when an external clock input is used, the ?max.? cycle time limit is ?dc? (no clock) for all devices. 3: measurements are taken in ec mode. the clko signal is measured on the osco pin. clko is low for the q1-q2 period (1/2 t cy ) and high for the q3-q4 period (1/2 t cy ).
? 2009 microchip technology inc. preliminary ds39937b-page 199 pic24f04ka201 family table 26-20: pll clock ti ming specifications (v dd = 1.8v to 3.6v) ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic (1) min typ (2) max units conditions os50 f plli pll input frequency range 4 ? 8 mhz ecpll, hspll modes os51 f sys pll output frequency range 16 ? 32 mhz os52 t lock pll start-up time (lock time) ?? 2ms os53 d clk clko stability (jitter) -2 1 2 % measured over 100 ms period note 1: these parameters are characterized but not tested in manufacturing. 2: data in ?typ? column is at 3.3v, 25c unless otherwise stated. parameters are for design guidance only and are not tested. table 26-21: ac characteristics: internal rc accuracy ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. characteristic min typ max units conditions internal frc accuracy @ 8 mhz (1) f20 frc -2 ? 2 % +25c 3.0v v dd 3.6v -5 ? 5 % -40c t a +85c note 1: frequency calibrated at 25c and 3.3v. osctun bits can be used to compensate for temperature drift. table 26-22: ac characteristics: internal rc accuracy ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. characteristic min typ max units conditions lprc @ 31 khz (1) f21 -15 ? 15 % +25c 3.0v v dd 3.6v -15 ? 15 % -40c t a +85c note 1: change of lprc frequency as v dd changes.
pic24f04ka201 family ds39937b-page 200 preliminary ? 2009 microchip technology inc. figure 26-4: clko and i/o ti ming characteristics note: refer to figure 26-2 for load conditions. i/o pin (input) i/o pin (output) di35 old value new value di40 do31 do32 table 26-23: clko and i/ o timing requirements ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. sym characteristic min typ (1) max units conditions do31 t io r port output rise time ? 10 25 ns do32 t io f port output fall time ? 10 25 ns di35 t inp intx pin high or low time (output) 20 ? ? ns di40 t rbp cnx high or low time (input) 2??t cy note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated.
? 2009 microchip technology inc. preliminary ds39937b-page 201 pic24f04ka201 family table 26-24: adc mo dule specifications ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min. typ max. units conditions device supply ad01 av dd module v dd supply greater of v dd ? 0.3 or 1.8 ? lesser of v dd + 0.3 or 3.6 v ad02 av ss module v ss supply v ss ? 0.3 ? v ss + 0.3 v reference inputs ad05 v refh reference voltage high av ss + 1.7 ? av dd v ad06 v refl reference voltage low av ss ?av dd ? 1.7 v ad07 v ref absolute reference voltage av ss ? 0.3 ? av dd + 0.3 v analog input ad10 v inh -v inl full-scale input span v refl ?v refh v (note 2) ad11 v in absolute input voltage av ss ? 0.3 ? av dd + 0.3 v ad12 v inl absolute v inl input voltage av ss ? 0.3 av dd /2 v ad17 r in recommended impedance of analog voltage source ??2.5k 10-bit adc accuracy ad20 b n r resolution ? 10 ? bits ad21 b inl integral nonlinearity ? 1 2 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad22 b dnl differential nonlinearity ? 1 1.5 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad23 b g err gain error ? 1 3 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad24 b e off offset error ? 1 2 lsb v inl = av ss = v refl = 0v, av dd = v refh = 3v ad25 b monotonicity (1) ? ? ? ? guaranteed note 1: the adc conversion result never decreases with an increase in the input voltage and has no missing codes. 2: measurements taken with external v ref + and v ref - used as the adc voltage reference.
pic24f04ka201 family ds39937b-page 202 preliminary ? 2009 microchip technology inc. table 26-25: adc conversion timing requirements (1) ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min. typ max. units conditions clock parameters ad50 t ad adc clock period 75 ? ? ns t cy = 75 ns, ad1con3 in default state ad51 t rc adc internal rc oscillator period ?250? ns conversion rate ad55 t conv conversion time ? 12 ? t ad ad56 f cnv throughput rate ? ? 500 ksps av dd 2.7v ad57 t samp sample time ? 1 ? t ad ad58 t acq acquisition time 750 ? ? ns (note 2) ad59 t swc switching time from convert to sample ?? (note 3) ad60 t dis discharge time 0.5 ? ? t ad clock parameters ad61 t pss sample start delay from setting sample bit (samp) 2?3t ad note 1: because the sample caps will eventually lose charge, clock rates below 10 khz can affect linearity performance, especially at elevated temperatures. 2: the time for the holding capacitor to acquire the ?new? input voltage when the voltage changes full scale after the conversion (v dd to v ss or v ss to v dd ). 3: on the following cycle of the device clock.
? 2009 microchip technology inc. preliminary ds39937b-page 203 pic24f04ka201 family table 26-26: reset, watchdog timer, oscill ator start-up timer, power-up timer and brown-out reset timing requirements ac characteristics standard operating conditions: 1.8v to 3.6v (unless otherwise stated) operating temperature -40c t a +85c for industrial param no. symbol characteristic min. typ (1) max. units conditions sy10 tmcl mclr pulse width (low) 2 ? ? s sy11 t pwrt power-up timer period 50 64 90 ms sy12 t por power-on reset delay 1 5 10 s sy13 t ioz i/o high-impedance from mclr low or watchdog timer reset ??100ns sy20 t wdt watchdog timer time-out period 0.85 1.0 1.15 ms 1.32 prescaler 3.4 4.0 4.6 ms 1:128 prescaler sy25 t bor brown-out reset pulse width 1 ? ? s sy35 t fscm fail-safe clock monitor delay ? 2 2.3 s sy45 t rst configuration update time ? 20 ? s t vreg on-chip voltage regulator output delay ?10? s sy55 t lock pll start-up time ? 1 ? ms sy65 t ost oscillator start-up time ? 1024 ? t osc sy75 t frc fast rc oscillator start-up time ? 1 1.5 s sy85 t lprc low-power oscillator start-up time ??100 s note 1: data in ?typ? column is at 3.3v, 25c unless otherwise stated.
pic24f04ka201 family ds39937b-page 204 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 205 pic24f04ka201 family 27.0 packaging information 27.1 package marking information legend: xx...x product-specific information y year code (last digit of calendar year) yy year code (last 2 digits of calendar year) ww week code (week of january 1 is week ?01?) nnn alphanumeric traceability code pb-free jedec designator for matte tin (sn) * this package is pb-free. the pb-free jedec designator ( ) can be found on the outer packaging for this package. note : in the event the full microchip part number cannot be marked on one line, it will be carried over to the next line, thus limiting the number of available characters for customer-specific information. 3 e 3 e 14-lead pdip xxxxxxxxxxxxxx xxxxxxxxxxxxxx yywwnnn example pic24f04ka200 0910017 14-lead tssop xxxxxxxx yyww nnn example 24f4ka 0910 017 -i/p 3 e 3 e 20-lead pdip xxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxx yywwnnn example pic24f04ka201-i/p 0910017 3 e
pic24f04ka201 family ds39937b-page 206 preliminary ? 2009 microchip technology inc. 20-lead soic (.300?) xxxxxxxxxxxxxx xxxxxxxxxxxxxx xxxxxxxxxxxxxx yywwnnn example pic24f04ka201 -i/so 0910017 3 e 20-lead qfn example 3 e xxxxxx xxxxxx yywwnnn xxxxxx 24f04 ka201 0910017 /mq 20-lead ssop xxxxxxxxxxx xxxxxxxxxxx yywwnnn example 24f04ka201 -i/ss 0910017 3 e
? 2009 microchip technology inc. preliminary ds39937b-page 207 pic24f04ka201 family 27.2 package details the following sections give the technical details of the packages. 
    
     

     !"#$%! & '(!%&! %(
%")% %  % "   *$%+  %  % , & 
 "-"

%!"&
"$ 

% ! 
 
"$ 

% ! 
  
%#".   "  & 
"%
   -/0 1+21 & 
 
%#%!
))%
!%%
     3
% &
%! % 4" ) '   % 
  4 $%

%"% %% 255)))&
  
&5 4 6% 7+8- & 
9&% 7 7: ; 7!&( 
$ 7  %  1+
%
%  < <  
""4 4  0 , 0 1 %
%  0 < < 
!" %

!" ="% -  , ,0 
""4="% -  0 > : 9%  ,0 0 0  %
% 9 0 , 0 9" 4  >  0 6  9"="% ( 0 ?  9
) 9"="% (  >  : 
) * 1 < < , n e1 d note 1 12 3 e c eb a2 l a a1 b1 be 
   

  ) +01
pic24f04ka201 family ds39937b-page 208 preliminary ? 2009 microchip technology inc. 
  !" #"$% # &  #!  '   !##&
     !"#$%! & '(!%&! %(
%")% %  % "   & 
 "-"

%!"&
"$ 

% ! 
 
"$ 

% ! 
  
%#"0&&   " , & 
"%
   -/0 1+2 1 & 
 
%#%!
))%
!%%
   -32 $ & 
'! !)%
!%%
 '$
$
&%
 !
 
   3
% &
%! % 4" ) '   % 
  4 $%

%"% %% 255)))&
  
&5 4 6% 99- - & 
9&% 7 7: ; 7!&( 
$ 7  %  ?01+ : 8 %  < <  
""4 4  >  0 %"
$$  0 < 0 : ="% - ?1+ 
""4="% - ,  0 
""49%   0 0 3
%9% 9 0 ? 0 3
% % 9 -3 3
%  @ < >@ 9" 4   <  9"="% (  < , note 1 d n e e1 1 2 e b c a a1 a2 l1 l 
   

  ) +>1
? 2009 microchip technology inc. preliminary ds39937b-page 209 pic24f04ka201 family (
    
     

      !"#$%! & '(!%&! %(
%")% %  % "   *$%+  %  % , & 
 "-"

%!"&
"$ 

% ! 
 
"$ 

% ! 
  
%#".   "  & 
"%
   -/0 1+2 1 & 
 
%#%!
))%
!%%
     3
% &
%! % 4" ) '   % 
  4 $%

%"% %% 255)))&
  
&5 4 6% 7+8- & 
9&% 7 7: ; 7!&( 
$ 7  %  1+
%
%  < <  
""4 4  0 , 0 1 %
%  0 < < 
!" %

!" ="% - , , ,0 
""4="% -  0 > : 9%  > , ?  %
% 9 0 , 0 9" 4  >  0 6  9"="% ( 0 ?  9
) 9"="% (  >  : 
) * 1 < < , n e1 note 1 d 123 a a1 a2 l e b1 b e c eb 
   

  ) +1
pic24f04ka201 family ds39937b-page 210 preliminary ? 2009 microchip technology inc. (
  #"$% # &  ##  )'   ##&
     !"#$%! & '(!%&! %(
%")% %  % "   & 
 "-"

%!"&
"$ 

% ! 
 
"$ 

% ! 
  
%#"&&   " , & 
"%
   -/0 1+2 1 & 
 
%#%!
))%
!%%
   -32 $ & 
'! !)%
!%%
 '$
$
&%
 !
 
   3
% &
%! % 4" ) '   % 
  4 $%

%"% %% 255)))&
  
&5 4 6% 99- - & 
9&% 7 7: ; 7!&( 
$ 7  %  ?01+ : 8 %  < <  
""4 4  ?0 0 >0 %"
$$  0 < < : ="% -  > > 
""4="% - 0 0, 0? : 9%  ?  0 3
%9% 9 00 0 0 3
% % 9 0-3 9" 4   < 0 3
%  @ @ >@ 9"="% (  < ,> l l1 a2 c e b a1 a 12 note 1 e1 e d n 
   

  ) +1
? 2009 microchip technology inc. preliminary ds39937b-page 211 pic24f04ka201 family (
  # &  #&  *+ ,')   #&-     !"#$%! & '(!%&! %(
%")% %  % "   *$%+  %  % , & 
 "-"

%!"&
"$ 

% ! 
 
"$ 

% ! 
  
%#"0&&   "  & 
"%
   -/0 1+2 1 & 
 
%#%!
))%
!%%
   -32 $ & 
'! !)%
!%%
 '$
$
&%
 !
 
   3
% &
%! % 4" ) '   % 
  4 $%

%"% %% 255)))&
  
&5 4 6% 99- - & 
9&% 7 7: ; 7!&( 
$ 7  %  1+ : 8 %  < < ?0 
""4 4  0 < < %"
$$*   < , : ="% - ,1+ 
""4="% - 01+ : 9%  >1+ + &$ a
%
b 0 < 0 3
%9% 9  <  3
% % 9 -3 3
% @ < >@ 9" 4   < ,, 9"="% ( , < 0 
" $%
0@ < 0@ 
" $%1
%%
& 0@ < 0@ d e e1 e b 123 note 1 a a1 a2 h h c l1 l n 
   

  ) +1
pic24f04ka201 family ds39937b-page 212 preliminary ? 2009 microchip technology inc. 20-lead plastic quad flat, no lead package (mq) C 5x5x0.9 mm body [qfn] note: for the most current package drawings, please see the microchip packaging specification located at http://www.microchip.com/packaging microchip technology drawing c04-120a
? 2009 microchip technology inc. preliminary ds39937b-page 213 pic24f04ka201 family appendix a: revision history revision a (february 2009) original data sheet for the pic24f04ka201 family of devices. revision b (may 2009) the title was changed. section 2.0 ?guidelines for getting started with 16-bit microcontrollers? was added. extensive changes to section 26.0 ?electrical characteristics? . minor text edits throughout document.
pic24f04ka201 family ds39937b-page 214 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 215 pic24f04ka201 family index a a/d 10-bit high-speed a/d converter ............................ 143 conversion timing requirements ............................ 202 module specifications .............................................. 201 reset, watchdog timer, oscillator start-up timer, power-up timer and brown-out reset timing requirements ............................ 203 a/d converter analog input model .................................................. 150 transfer function ..................................................... 151 ac characteristics capacitive loading requirements on output pins ...................................................... 197 comparator .............................................................. 196 comparator voltage reference settling time ............................................ 196, 200 ctmu current source ............................................. 196 internal rc accuracy ............................................... 199 load conditions and requirements ......................... 197 temperature and voltage specific ations ................. 197 assembler mpasm assembler .................................................. 174 b baud rate generator setting as a bus master ........................................... 127 block diagrams 10-bit high-speed a/d converter ............................ 144 16-bit timer1 ........................................................... 101 accessing program memory with table instructions .............................................. 40 call stack frame ..................................................... 37 comparator module ................................................. 153 comparator voltage reference ............................... 157 cpu programmer?s model ......................................... 21 ctmu connections and internal configuration for capacitance measurement ......................... 159 ctmu typical connections and internal configuration for pulse delay generation ....... 160 ctmu typical connections and internal configuration for time measurement .............. 160 data access from program space address generation ........................................... 38 high/low-voltage detect (hlvd) ............................ 141 i 2 c module ............................................................... 126 individual comparator configurations ...................... 154 input capture ........................................................... 109 output compare ...................................................... 114 pic24f cpu core ..................................................... 20 pic24f04ka201 family (general) ............................ 10 psv operation ........................................................... 41 reset system ............................................................. 51 shared i/o port structure .......................................... 99 simplified uart ....................................................... 133 spi1 module (enhanced buffer mode) .................... 119 spi1 module (standard buffer mode) ...................... 118 system clock ............................................................. 81 timer2 (16-bit synchronous mode) ......................... 105 timer2/3 (32-bit mode) ............................................ 104 timer3 (16-bit synchronous mode) ......................... 105 watchdog timer (wdt) ........................................... 170 brown-out reset (bor) ..................................................... 55 c c compilers mplab c18 ............................................................. 174 mplab c30 ............................................................. 174 charge time measurement unit. see ctmu. code examples erasing a program memory row, ?c? language code ............................................ 47 erasing a program memory row, assembly language code ................................ 46 i/o port write/read ................................................. 100 initiating a programming sequence, ?c? language code ............................................ 49 initiating a programming sequence, assembly language code ................................ 49 loading the write buffers, ?c? language code ......... 48 loading the write buffers, assembly language code ................................................. 48 programming a single word of flash program memory ..................................... 49 pwrsav instruction syntax ..................................... 91 sequence for clock switching ................................... 88 code protection ............................................................... 171 comparator ...................................................................... 153 comparator voltage reference ....................................... 157 configuring .............................................................. 157 configuration bits ............................................................ 163 core features ...................................................................... 7 cpu alu ............................................................................ 23 control registers ....................................................... 22 core registers ........................................................... 20 programmer?s model ................................................. 19 ctmu measuring capacitance ........................................... 159 measuring time ....................................................... 160 pulse delay and generation .................................... 160 customer change notification service ............................ 218 customer notification service ......................................... 218 customer support ............................................................ 218 d data memory address space .......................................................... 27 memory map .............................................................. 27 near data space ....................................................... 28 organization .............................................................. 28 sfr space ................................................................ 28 software stack .......................................................... 37 space width .............................................................. 27 dc characteristics brown-out reset trip points .................................... 188 comparator .............................................................. 196 comparator voltage reference ............................... 196 high/low-voltage detect ......................................... 187 i/o pin input specifications ..................................... 194 i/o pin output specifications ................................... 195 idle current i idle ..................................................... 189 operating current i dd .............................................. 188 power-down current i pd ......................................... 191 program memory ..................................................... 195 temperature and voltage specific ations ................. 187
pic24f04ka201 family ds39937b-page 216 preliminary ? 2009 microchip technology inc. deep sleep bor (dsbor) ............................................... 56 development support ...................................................... 173 device features (summary) ................................................ 9 doze mode ......................................................................... 97 e electrical characteristics absolute maximum ratings ..................................... 185 thermal operating conditions ................................. 186 v/f graphs ............................................................... 186 equations a/d conversion clock period .................................. 150 baud rate reload value ......................................... 127 calculating the pwm period .................................... 112 calculation for maximum pwm resolution .............. 112 device and spi clock speed relationship .............. 124 uart baud rate with brgh = 0 ............................ 134 uart baud rate with brgh = 1 ............................ 134 errata ................................................................................... 5 f flash program memory control registers ....................................................... 44 enhanced icsp operation ......................................... 44 operations ................................................................. 44 programming algorithm ............................................. 46 rtsp operation ......................................................... 44 table instructions ....................................................... 43 h high/low-voltage detect (hlvd) .................................... 141 i i/o ports analog port pins configuration ................................ 100 input change notification ......................................... 100 open-drain configuration ........................................ 100 parallel (pio) ............................................................. 99 i 2 c clock rates .............................................................. 127 communicating as master in single master environment ......................................... 125 pin remapping options ........................................... 125 reserved addresses ................................................ 127 slave address masking ........................................... 127 in-circuit serial programming .......................................... 171 input capture ................................................................... 109 instruction set opcode symbols ...................................................... 178 overview .................................................................. 179 summary .................................................................. 177 instruction-based power-saving modes ............................ 91 deep sleep ................................................................ 92 idle ............................................................................. 92 sleep .......................................................................... 91 inter-integrated circuit. see i 2 c. internet address ............................................................... 218 interrupts alternate interrupt vector table (aivt) ..................... 57 implemented vectors ................................................. 58 interrupt vector table (ivt) ....................................... 57 reset sequence ........................................................ 57 setup and service procedures .................................. 80 trap vectors .............................................................. 58 vector table ............................................................... 57 m microchip internet web site ............................................. 218 mplab asm30 assembler, linker, librarian .................. 174 mplab icd 2 in-circuit debugger .................................. 175 mplab ice 2000 high-performance universal in-circuit emulator ................................... 175 mplab integrated development environment software ............................................. 173 mplab pm3 device programmer ................................... 175 mplab real ice in-circuit emulator system ............... 175 mplink object linker/mplib object librarian ............... 174 n near data space ............................................................... 28 o oscillator configuration clock switching ......................................................... 87 sequence .......................................................... 87 configuration values for clock selection .................. 82 cpu clocking scheme .............................................. 82 initial configuration on por ...................................... 82 output compare continuous output pulse generation ...................... 111 pwm mode period and duty cycle calculations ................ 113 single output pulse generation .............................. 111 p packaging details ...................................................................... 207 marking .................................................................... 205 picstart plus development programmer .................... 176 pinout descriptions ...................................................... 11?13 power-saving features ..................................................... 91 clock frequency and clock switching ...................... 91 product identification system .......................................... 220 program and data memory access using table instructions ................................ 39 program space visibility ............................................ 40 program and data memory spaces interfacing .................................................................. 37 program memory address space .......................................................... 25 memory map .............................................................. 25 program verification ........................................................ 171 pulse-width modulation. see pwm. r reader response ............................................................ 219 reference clock output .................................................... 88 register maps a/d converter (adc) ................................................. 34 clock control ............................................................. 35 cpu core .................................................................. 29 ctmu ........................................................................ 34 deep sleep ................................................................ 35 dual comparator ....................................................... 35 i 2 c ............................................................................. 32 icn ............................................................................ 30 input capture ............................................................. 31 interrupt controller ..................................................... 30 nvm ........................................................................... 36 output compare ........................................................ 31 pad configuration ...................................................... 33
? 2009 microchip technology inc. preliminary ds39937b-page 217 pic24f04ka201 family pmd ........................................................................... 36 porta ....................................................................... 33 portb ....................................................................... 33 spi ............................................................................. 32 timer .......................................................................... 31 uart ......................................................................... 32 registers ad1chs (a/d input select) ..................................... 148 ad1con1 (a/d control 1) ....................................... 145 ad1con2 (a/d control 2) ....................................... 146 ad1con3 (a/d control 3) ....................................... 147 ad1cssl (a/d input scan select, low) ................. 149 ad1pcfg (a/d port configuration) ......................... 149 clkdiv (clock divider) ............................................. 85 cmstat (comparator status) ................................. 156 cmxcon (comparator x control) ............................ 155 corcon (core control) ........................................... 61 corcon (cpu control) ........................................... 23 ctmucon (ctmu control) .................................... 161 ctmuicon (ctmu current control) ...................... 162 cvrcon (comparator voltage reference control) .......................................... 158 devid (device id) ................................................... 169 devrev (device revision) ..................................... 169 dscon (deep sleep control) ................................... 95 dswsrc (deep sleep wake-up source) ................. 96 fds (deep sleep configuration) ............................. 168 fgs (general segment configuration) .................... 163 ficd (in-circuit debugger configuration) ................ 167 fosc (oscillator configuration) .............................. 165 foscsel (oscillator selection configuration) ........ 164 fpor (reset configuration) .................................... 167 fwdt (watchdog timer configuration) .................. 166 hlvdcon (high/low-voltage detect control) ........ 142 i2c1con (i2c1 control) .......................................... 128 i2c1msk (i2c1 slave mode address mask) ........... 132 i2c1stat (i2c1 status) .......................................... 130 ic1con (input capture 1 control) ........................... 110 iec0 (interrupt enable control 0) .............................. 67 iec1 (interrupt enable control 1) .............................. 68 iec4 (interrupt enable control 4) .............................. 69 ifs0 (interrupt flag status 0) .................................... 64 ifs1 (interrupt flag status 1) .................................... 65 ifs4 (interrupt flag status 4) .................................... 66 intcon1 (interrupt control 1) ................................... 62 inttreg (interrupt control and status) .................... 79 ipc0 (interrupt priority control 0) .............................. 70 ipc1 (interrupt priority control 1) .............................. 71 ipc16 (interrupt priority control 16) .......................... 77 ipc18 (interrupt priority control 18) .......................... 78 ipc19 (interrupt priority control 19) .......................... 78 ipc2 (interrupt priority control 2) .............................. 72 ipc3 (interrupt priority control 3) .............................. 73 ipc4 (interrupt priority control 4) .............................. 74 ipc5 (interrupt priority control 5) .............................. 75 ipc7 (interrupt priority control 7) .............................. 76 nvmcon (flash memory control) ............................ 45 oc1con (output compare 1 control) .................... 115 osccon (oscillator control) .................................... 83 osctun (frc oscillator tune) ................................ 86 padcfg1 (pad configuration control) ........... 116, 132 rcon (reset control) ............................................... 52 refocon (reference oscillator control) ................ 89 spi1con1 (spi1 control 1) .................................... 122 spi1con2 (spi1 control 2) .................................... 123 spi1stat (spi1 status and control) ...................... 120 sr (alu status) .............................................. 22, 60 t1con (timer1 control) ......................................... 102 t2con (timer2 control) ......................................... 106 t3con (timer3 control) ......................................... 107 u1mode (uart1 mode) ........................................ 136 u1rxreg (uart1 receive) .................................. 140 u1sta (uart1 status and control) ....................... 138 u1txreg (uart1 transmit) ................................. 140 resets clock source selection ............................................. 53 delay times ............................................................... 54 device times ............................................................. 54 rcon flags operation ............................................. 53 sfr states ................................................................ 56 revision history ............................................................... 213 s selective peripheral power control ................................... 97 serial peripheral interface. see spi. sfr space ........................................................................ 28 software simulator (mplab sim) ................................... 174 software stack .................................................................. 37 t timer1 ............................................................................. 101 timer2/3 .......................................................................... 103 timing diagrams clko and i/o .......................................................... 200 external clock ......................................................... 198 timing requirements clko and i/o .......................................................... 200 external clock ......................................................... 198 pll clock specifications ......................................... 199 u uart ............................................................................... 133 baud rate generator (brg) ................................... 134 break and sync transmit sequence ....................... 135 irda support ............................................................ 135 operation of u1cts and u1rts control pins ........ 135 receiving in 8-bit or 9-bit data mode ..................... 135 transmitting in 8-bit data mode .............................. 135 transmitting in 9-bit data mode .............................. 135 w watchdog timer deep sleep (dswdt) ............................................. 171 watchdog timer (wdt) ................................................... 170 windowed operation ............................................... 170 www address ................................................................ 218 www, on-line support .................... .................................. 5
pic24f04ka201 family ds39937b-page 218 preliminary ? 2009 microchip technology inc. notes:
? 2009 microchip technology inc. preliminary ds39937b-page 219 pic24f04ka201 family the microchip web site microchip provides online support via our www site at www.microchip.com. this web site is used as a means to make files and information easily available to customers. accessible by using your favorite internet browser, the web site contains the following information: ? product support ? data sheets and errata, application notes and sample programs, design resources, user?s guides and hardware support documents, latest software releases and archived software ? general technical support ? frequently asked questions (faq), technical support requests, online discussion groups, microchip consultant program member listing ? business of microchip ? product selector and ordering guides, latest microchip press releases, listing of seminars and events, listings of microchip sales offices, distributors and factory representatives customer change notification service microchip?s customer notification service helps keep customers current on microchip products. subscribers will receive e-mail notification whenever there are changes, updates, revisions or errata related to a specified product family or development tool of interest. to register, access the microchip web site at www.microchip.com, click on customer change notification and follow the registration instructions. customer support users of microchip products can receive assistance through several channels: ? distributor or representative ? local sales office ? field application engineer (fae) ? technical support ? development systems information line customers should contact their distributor, representative or field application engineer (fae) for support. local sales offices are also available to help customers. a listing of sales offices and locations is included in the back of this document. technical support is available through the web site at: http://support.microchip.com
pic24f04ka201 family ds39937b-page 220 preliminary ? 2009 microchip technology inc. reader response it is our intention to provide you with the best documentation possible to ensure successful use of your microchip prod- uct. if you wish to provide your comments on organization, clarity, subject matter, and ways in which our documentation can better serve you, please fax your comments to the technical publications manager at (480) 792-4150. please list the following information, and use this outline to provide us with your comments about this document. to : technical publications manager re: reader response total pages sent ________ from: name company address city / state / zip / country telephone: (_______) _________ - _________ application (optional): would you like a reply? y n device: literature number: questions: fax: (______) _________ - _________ ds39937b pic24f04ka201 family 1. what are the best features of this document? 2. how does this document meet your hardware and software development needs? 3. do you find the organization of this document easy to follow? if not, why? 4. what additions to the document do you think would enhance the structure and subject? 5. what deletions from the document could be made without affecting the overall usefulness? 6. is there any incorrect or misleading information (what and where)? 7. how would you improve this document?
? 2009 microchip technology inc. preliminary ds39937b-page 221 pic24f04ka201 family product identification system to order or obtain information, e. g., on pricing or delivery, refer to the factory or the listed sales office . architecture 24 = 16-bit modified harvard without dsp flash memory family f = flash program memory product group ka2 = general purpose microcontrollers pin count 00 = 14-pin 01 = 20-pin temperature range i = -40 c to +85 c (industrial) package p = pdip sl = soic, narrow so = soic ss = ssop mq = qfn st = tssop pattern three-digit qtp, sqtp, code or special requirements (blank otherwise) es = engineering sample examples: a) pic24f04ka201-i/mq: general purpose, 16-kbyte program memory, 20-pin, industrial temp., qfn package. microchip trademark architecture flash memory family program memory size (kb) product group pin count temperature range package pattern pic 24 f 04 ka2 01 t - i / ss - xxx tape and reel flag (if applicable)
ds39937b-page 222 preliminary ? 2009 microchip technology inc. americas corporate office 2355 west chandler blvd. chandler, az 85224-6199 tel: 480-792-7200 fax: 480-792-7277 technical support: http://support.microchip.com web address: www.microchip.com atlanta duluth, ga tel: 678-957-9614 fax: 678-957-1455 boston westborough, ma tel: 774-760-0087 fax: 774-760-0088 chicago itasca, il tel: 630-285-0071 fax: 630-285-0075 cleveland independence, oh tel: 216-447-0464 fax: 216-447-0643 dallas addison, tx tel: 972-818-7423 fax: 972-818-2924 detroit farmington hills, mi tel: 248-538-2250 fax: 248-538-2260 kokomo kokomo, in tel: 765-864-8360 fax: 765-864-8387 los angeles mission viejo, ca tel: 949-462-9523 fax: 949-462-9608 santa clara santa clara, ca tel: 408-961-6444 fax: 408-961-6445 toronto mississauga, ontario, canada tel: 905-673-0699 fax: 905-673-6509 asia/pacific asia pacific office suites 3707-14, 37th floor tower 6, the gateway harbour city, kowloon hong kong tel: 852-2401-1200 fax: 852-2401-3431 australia - sydney tel: 61-2-9868-6733 fax: 61-2-9868-6755 china - beijing tel: 86-10-8528-2100 fax: 86-10-8528-2104 china - chengdu tel: 86-28-8665-5511 fax: 86-28-8665-7889 china - hong kong sar tel: 852-2401-1200 fax: 852-2401-3431 china - nanjing tel: 86-25-8473-2460 fax: 86-25-8473-2470 china - qingdao tel: 86-532-8502-7355 fax: 86-532-8502-7205 china - shanghai tel: 86-21-5407-5533 fax: 86-21-5407-5066 china - shenyang tel: 86-24-2334-2829 fax: 86-24-2334-2393 china - shenzhen tel: 86-755-8203-2660 fax: 86-755-8203-1760 china - wuhan tel: 86-27-5980-5300 fax: 86-27-5980-5118 china - xiamen tel: 86-592-2388138 fax: 86-592-2388130 china - xian tel: 86-29-8833-7252 fax: 86-29-8833-7256 china - zhuhai tel: 86-756-3210040 fax: 86-756-3210049 asia/pacific india - bangalore tel: 91-80-3090-4444 fax: 91-80-3090-4080 india - new delhi tel: 91-11-4160-8631 fax: 91-11-4160-8632 india - pune tel: 91-20-2566-1512 fax: 91-20-2566-1513 japan - yokohama tel: 81-45-471- 6166 fax: 81-45-471-6122 korea - daegu tel: 82-53-744-4301 fax: 82-53-744-4302 korea - seoul tel: 82-2-554-7200 fax: 82-2-558-5932 or 82-2-558-5934 malaysia - kuala lumpur tel: 60-3-6201-9857 fax: 60-3-6201-9859 malaysia - penang tel: 60-4-227-8870 fax: 60-4-227-4068 philippines - manila tel: 63-2-634-9065 fax: 63-2-634-9069 singapore tel: 65-6334-8870 fax: 65-6334-8850 taiwan - hsin chu tel: 886-3-6578-300 fax: 886-3-6578-370 taiwan - kaohsiung tel: 886-7-536-4818 fax: 886-7-536-4803 taiwan - taipei tel: 886-2-2500-6610 fax: 886-2-2508-0102 thailand - bangkok tel: 66-2-694-1351 fax: 66-2-694-1350 europe austria - wels tel: 43-7242-2244-39 fax: 43-7242-2244-393 denmark - copenhagen tel: 45-4450-2828 fax: 45-4485-2829 france - paris tel: 33-1-69-53-63-20 fax: 33-1-69-30-90-79 germany - munich tel: 49-89-627-144-0 fax: 49-89-627-144-44 italy - milan tel: 39-0331-742611 fax: 39-0331-466781 netherlands - drunen tel: 31-416-690399 fax: 31-416-690340 spain - madrid tel: 34-91-708-08-90 fax: 34-91-708-08-91 uk - wokingham tel: 44-118-921-5869 fax: 44-118-921-5820 w orldwide s ales and s ervice 03/26/09


▲Up To Search▲   

 
Price & Availability of PIC24F04KA200T-IMQ

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X